Utilities and Helpers¶
Interfacing with data files and results from Fortran AMICA¶
- amica.utils.load_data(filename, *, dtype=<class 'numpy.float32'>, shape=None)¶
Load binary data file that saved for use with Fortran AMICA.
- Parameters:
- filenamestr or Path
The path to the input binary file.
- dtypedata-type
The desired data-type for the loaded array. Default is np.float32.
- shapetuple of int
The shape of the array to load.
- Returns:
- datanp.ndarray
The Fortran-contiguous array that was loaded.
Notes
Fortran stores arrays in column-major order, and the Fortran program expectes data in shape (n_features, n_samples). So when loading data for use in Python, you should reshape to (n_features, n_samples) and then transpose to (n_samples, n_features) to match the common Python convention.
Examples
>>> data = load_data('data.bin', shape=(64, 1000)).T
- amica.utils.load_fortran_results(fortran_outdir, *, n_components, n_mixtures, n_features=None)¶
Load results from a completed Fortran AMICA run for comparison.
- amica.utils.load_initial_weights(fortran_outdir, *, n_components, n_mixtures)¶
Load w_init, sbeta_init, and mu_init binary files from a Fortran AMICA run.
- amica.utils.write_data(data, filename)¶
Save data to a binary file in Fortran-compatible format.
- Parameters:
- dataarray-like
The data of shape (n_samples, n_features) to save. Will be converted to a Fortran-contiguous array of type float32.
- filenamestr or Path
The path to the output binary file.
- Returns:
- datanp.ndarray
The Fortran-contiguous array that was saved.
- pathPath
The path to the saved file.
- amica.utils.write_param_file(fpath, *, files, outdir, data, **kwargs)¶
Write a Fortran AMICA parameter file.
- Parameters:
- fpathstr or Path
The path to the output parameter file.
- datanp.ndarray
The data array to write to the file.
- **kwargsdict
Additional parameters to write to the file.
- Returns:
- pathPath
The path to the saved parameter file.