Misc Utilities

Configuration

ourparams.py
  • Intended to hold all standard arguments, either in
    • default command line settings OR

    • via hardcoded defaults

  • Provides command line parsing

  • Provides explicit settings for sampler parameters

RIFT.misc.ourparams.ParseStandardArguments()
RIFT.misc.ourparams.PopulatePrototypeSignal(opts)
RIFT.misc.ourparams.PopulateSamplerParameters(sampler, theEpochFiducial, tEventFiducial, distBoundGuess, Psig, opts)
RIFT.misc.ourparams.PopulateTriggerSNRs(opts)

Note

DEPRECATED: ourparams is deprecated and not used in current production code. Use alternative configuration methods instead.

Sky Coordinates

RIFT.misc.sky_rotations.assign_sky_frame(det0, det1, theEpochFiducial)
RIFT.misc.sky_rotations.network_to_physical(theta, phi, inverse_frame=None, xpy=<module 'numpy' from '/opt/hostedtoolcache/Python/3.11.18/x64/lib/python3.11/site-packages/numpy/__init__.py'>)

Map sampled network-frame angles back to physical equatorial angles.

RIFT.misc.sky_rotations.physical_to_network(theta, phi, frame=None, xpy=<module 'numpy' from '/opt/hostedtoolcache/Python/3.11.18/x64/lib/python3.11/site-packages/numpy/__init__.py'>)

Map physical equatorial angles into the assigned network frame.

RIFT.misc.sky_rotations.rotate_sky_backwards(th, ph, frmInverse=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
RIFT.misc.sky_rotations.rotate_sky_backwards_scalar(theta, phi, frmInverse=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
RIFT.misc.sky_rotations.rotate_sky_forwards(th, ph, frm=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
RIFT.misc.sky_rotations.rotate_sky_forwards_scalar(theta, phi, frm=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))

Spoke Management

RIFT.misc.spokes.ChooseWaveformParams_to_spoke_label(P, digits=4, is_eccentric=False)
RIFT.misc.spokes.ChooseWaveformParams_to_spoke_mass(P, digits=4)
RIFT.misc.spokes.CleanSpokeEntries(spoke_entries, digits=4)
RIFT.misc.spokes.FitSpokeNearPeak(xvals, lnLVals, deltaLogL=10, refinement_scale_min=0.2, **kwargs)
RIFT.misc.spokes.Line_to_spoke_entry(line, digits=4, is_eccentric=False)
RIFT.misc.spokes.Line_to_spoke_label(line, digits=4, is_eccentric=False)
RIFT.misc.spokes.LoadSpokeDAT(fname, is_eccentric=False, digits=4)
RIFT.misc.spokes.LoadSpokeXML(fname, is_eccentric=False, digits=4)
RIFT.misc.spokes.Refine(xvals, lnLVals, xmin=None, deltaLogL=10, npts=10, refinement_scale_min=0.2, **kwargs)

Refine(xvals,lnLVals) takes a 1d grid of lnL(x) and returns a simple grid refinement guess. If the maximum is at or very near an edge (1 or two samples). Refinement by default fits to top 30%

Coordinate Tools

RIFT.misc.tools.McqToMtot(Mc, q)
RIFT.misc.tools.McqTom1m2(Mc, q)
RIFT.misc.tools.Mcqchi1chi2Tomu1mu2mu3(mc, q, chi1, chi2)

chirpmass, q, chi1, chi2 to mu1, mu2, mu3

RIFT.misc.tools.convert_Mcqchi1chi2_to_mu1mu2(parameters)

Convert Mc, q, chi1, chi2 to mu1, mu2 and add them to parameters.

Parameters

parameters: dict

Returns

converted_parameters: dict

RIFT.misc.tools.convert_m1m2chi1chi2_to_Mcqmu1mu2(parameters)

Convert m1, m2, chi1, chi2 to Mc, q, mu1, mu2 and add them to parameters.

Parameters

parameters: dict

Returns

converted_parameters: dict

RIFT.misc.tools.convert_mu1mu2qchi2_to_Mcchi1(parameters)

Convert mu1, mu2, q, chi2 to Mc, chi1 and add them to parameters.

Parameters

parameters: dict

Returns

converted_parameters: dict

RIFT.misc.tools.etaToq(eta)

eta=m1*m2/(m1+m2)**2 to q=m2/m1

RIFT.misc.tools.m1m2(Mc, eta)
RIFT.misc.tools.m1m2ToMc(m1, m2)
RIFT.misc.tools.m1m2chi1chi2Tomu1mu2qchi2Jacobian(Mc, q)

Jacobian of the transformation from m1, m2, chi1, chi2 to mu1, mu2, q, chi2

RIFT.misc.tools.mu1mu2etaToMc(mu1, mu2, eta)

Convert mu1, mu2, eta=m1*m2/(m1+m2)**2 into chirpmass using bisection search.

RIFT.misc.tools.mu1mu2qchi2ToMcqchi1chi2(mu1, mu2, q, chi2)

mu1, mu2, q=m2/m1, chi2 to chirpmass, q, chi1, chi2

RIFT.misc.tools.mu2Mcetachi2Tochi1(mu2, Mc, eta, chi2)

mu2, chirpmass, eta=m1*m2/(m1+m2)**2, chi2 to chi1

RIFT.misc.tools.psi0(Mc)

chirpmass to the 0PN phase coefficient

RIFT.misc.tools.psi2(Mc, eta)

chirpmass and eta=m1*m2/(m1+m2)**2 to the 1PN phase coefficient

RIFT.misc.tools.psi3(Mc, q, a1z, a2z)
RIFT.misc.tools.qToeta(q)

q=m2/m1 to eta=m1*m2/(m1+m2)**2

RIFT.misc.tools.qa1za2zTobeta(q, a1z, a2z)
RIFT.misc.tools.transform_m1m2s1zs2z_mu1mu2qs2z(m1, m2, s1z, s2z)

component masses: m1, m2 and z-components of spins: s1z, s2z to mu1, mu2, q=m2/m1, s2z

RIFT.misc.tools.transform_mu1mu2qs2z_m1m2s1zs2z(mu1, mu2, q, s2z)

mu1, mu2, q=m2/m1, z-component of secondary spin to component masses: m1, m2 and z-components of spins: s1z, s2z

Simulation Weighting

RIFT.misc.weight_simulations.AverageSimulationWeights(param_list, length_list, sigma_list, prior_volume_list=None, weight_at_intrinsic='sigma')

AverageSimulationWeights returns the factors W_k appearing in a simple average over N simulations, for example for the integral value

I = sum_k W_k I_k

For backward compatibility, weights can be chosen that depend on
  • the number of draws for each simulation

  • the variance of each simulation

  • the parameter values of each simulation

  • priors, if the priors are provided as pre-integrated volumes (i.e., an array, one member per simulation). The user is assumed to have already identified volumes surrounding each simulation and integrated the prior accordingly. The user is responsible for the (in)accuracy of the resulting average, if the prior and likelihood vary significantly versus intrinsic parameters.

Specific implementations and use cases include:
  • single ILE run at fixed parameters, with different numbers of draws, either by variance-minimizing

    I = (sum_k I_k /sigma_k^2) / sum_k 1/sigma_k^2

    or by a simple average over the N simulations

    I = (sum_k I_k)/N N=# of simulations

  • multiple ILE runs at different parameters, accounting for an intrinsic prior volume Delta P_k for each simulation (normalized relative to the intrinsic prior: sum_k Delta P_k = (prior probability of lying in ellipsoid) << 1)

    I =( sum_k I_k Delta P_k /sigma_k^2)/ sum_k 1/sigma_k^2

XML Utilities

RIFT.misc.xmlutils.append_likelihood_result_to_xmldoc(xmldoc, loglikelihood, neff=0, converged=False, **cols)
RIFT.misc.xmlutils.append_samples_to_xmldoc(xmldoc, sampdict)
RIFT.misc.xmlutils.assign_id(row, i)
RIFT.misc.xmlutils.assign_time(row, t)
RIFT.misc.xmlutils.db_identify_param(db_fname, process_id, param)

Extract the event time for a given process ID. This may fail in the case that the event time was not given on the command line (rather in a pointer to a XML file) NOTE: This is definitely not the best way to do this.

RIFT.misc.xmlutils.db_to_samples(db_fname, tbltype, cols)

Pull samples from db_fname and return object that resembles a row from an XML table.

RIFT.misc.xmlutils.gps_add_seconds_exact(gps_seconds, gps_nanoseconds, offset_seconds)

Add float relative offsets to an exact GPS pair using integer nanoseconds.

The offset is rounded once to the SimInspiral schema’s nanosecond resolution. Absolute GPS arithmetic is never performed in float64, whose spacing at current epochs is coarser than some sub-sample time-posterior draws. Returns arrays (seconds, nanoseconds) with nanoseconds normalized to [0, 1e9); negative offsets and second-boundary carries are supported.

RIFT.misc.xmlutils.likelihood_to_snglinsp_row(table, loglikelihood, neff=0, converged=False, **cols)
RIFT.misc.xmlutils.samples_to_siminsp_row(table, colmap={}, **sampdict)

AMR Library

class RIFT.misc.amrlib.Cell(boundaries, center=None)

Bases: object

area()
divide()

Subdivide once along each dimension, recursively.

divide_if(testfunc, depth=1)

Subdivide once along each dimension, recursively.

intersects(other)
static make_cell_from_boundaries(inpt_pt, pts, symmetric=True)

Construct a ‘virtual cell’ from the extent of the points, centered on inpt_pt. If symmetric is True, the boundaries will be symmetric about the input point, if False, the cell will follow the extent of the points on either side.

refine()

Refine each cell such that 2*dim new cells are created. In contrast to divide, refine will place the center of each new cell at the midpoint along the boundary of the mother cell. Its dimensions will be the half width from the center to the edge on each side, except for the dimension along the splitting axis, where the dimension will be twice the half width of the original cell in that dimension (and on that side).

refine_full(return_cntr=True)

Refine each cell such that new cells are created along all permutations of a displacement vector with unit vectors in each dimension and the 0 vector.

translate(offset)

Translate this cell’s position and extent by offset.

exception RIFT.misc.amrlib.GriddingException(*args, **kwargs)

Bases: Exception

RIFT.misc.amrlib.apply_inv_transform(pts, intr_prms, mass_transform=None, spin_transform=None)
RIFT.misc.amrlib.apply_transform(pts, intr_prms, mass_transform=None, spin_transform=None)
RIFT.misc.amrlib.check_grid(grid, intr_prms, distance_coordinates, mass_lower_bound=1)

Check the validity of points in various coordinate spaces to ensure they are physical.

RIFT.misc.amrlib.check_mchirpeta(mchirp, eta)
RIFT.misc.amrlib.check_q(q)
RIFT.misc.amrlib.check_spins(spin)
RIFT.misc.amrlib.check_tau0tau3(tau0, tau3, flow=40)
RIFT.misc.amrlib.create_new_grid(cell, pts, max_level=6)

Subdivide until all cells are self contained - e.g. every cell contains no more than one pt from pts. If the number of divisions exceeds max_level, stop dividing.

RIFT.misc.amrlib.create_regular_grid_from_cell(cell, side_pts=5, return_cells=False)

Given a region (amrlib.Cell), grid it with side_pts to a dimension. If return_cells is given, the divided cells will be returned rather than the grid points. >>> import numpy >>> region = Cell(numpy.array([(-1., 1.), (-2., 2.)])) >>> grid, spacing = create_regular_grid_from_cell(region, side_pts=2) >>> print(grid) [[-1. -2.]

[-1. 2.] [ 1. -2.] [ 1. 2.]]

>>> print(spacing)
[ 2.  4.]
RIFT.misc.amrlib.deserialize_grid_cells(fname)

Unpacks a numpy file of level grid points and returns a cell collection. FIXME: This can’t yet distinguish the level of refinement. Need to teach it to pay attention to the resolution.

RIFT.misc.amrlib.grid_to_cells(grid, grid_spacing)
RIFT.misc.amrlib.grid_to_indices(pts, region, grid_spacing, check=True)

Convert points in a grid to their 1-D indices according to the grid extent in region, and grid spacing. If ‘check’ is True, ensure that all points exist within the expanded region before indexing — this tends to avoid more cryptic errors about indexing later on.

RIFT.misc.amrlib.init_grid_hdf(init_region, h5file, overlap_thresh, crd_sys, intr_prms=None, base_grp='rapidpe_grids')

Set up a new HDF5 file (h5file), truncating any existing file with this name. A new ‘folder’ called ‘base_grp’ is set up and the initial region with attribute ‘overlap_thresh’ is set up under it.

RIFT.misc.amrlib.load_grid_level(h5file, level, return_labels=False, base_grp='rapidpe_grids')

Load a set grid points (in the form of cells) from h5file. If level is None, return the base_grp, if level is -1, return the highest resolution available, otherwise an ArgumentError is raised if ‘level’ is not represented in the attributes of one of the levels stored under base_grp/’grids’

RIFT.misc.amrlib.load_init_region(h5file, get_labels=False, base_grp='rapidpe_grids')

Load the initial region for a set grid points (in the form of cells) from h5file.

RIFT.misc.amrlib.midpoint(pt1, pt2)
RIFT.misc.amrlib.ndim_offsets(ndim)
RIFT.misc.amrlib.pack_grid_cells(cells, resolution)

Pack the cell centers (grid points) into a convienient numpy array. The resolution of the grid is prepended for later use.

RIFT.misc.amrlib.prune_duplicate_pts(pts, region, grid_spacing)

Remove identical points from list.

RIFT.misc.amrlib.refine_regular_grid(grid, grid_spacing, return_cntr=False)

Given a regular grid in N dimensions with spacing given by grid_spacing, refine the grid by bisection along all dimensions. Returns the new grid and new spacing. The grid will not contain the center point by default (since it is assumed the point already exists in the unrefined grid, but this behavior can be changed by setting return_cntr to True. >>> region = Cell(numpy.array([(-1., 1.), (-2., 2.)])) >>> grid, spacing = create_regular_grid_from_cell(region, side_pts=2) >>> grid, spacing = refine_regular_grid(grid, spacing) >>> print(grid) [array([-2., -4.]), array([-2., -2.]), array([-1., -4.]), array([-1., -2.]), array([-2., 0.]), array([-2., 2.]), array([-1., 0.]), array([-1., 2.]), array([ 0., -4.]), array([ 0., -2.]), array([ 1., -4.]), array([ 1., -2.]), array([ 0., 0.]), array([ 0., 2.]), array([ 1., 0.]), array([ 1., 2.])] >>> print(spacing) [ 1. 2.]

RIFT.misc.amrlib.save_grid_cells_hdf(base_grp, cells, crd_sys, intr_prms=None, check=True)

Under the base_grp, a new level of grid points is saved. It will create a subgroup called “grids” if it does not already exist. Under this subgroup, levels are created sequentially, the function looks for the last level (e.g. the subsubgroup with the largest “level” attribute, and appends a new level with +1 to that number. If check is enabled (that is the default), a safety check against the new level versus the last level is made to ensure the resolution is a factor of two smaller.

RIFT.misc.amrlib.serialize_grid_cells(level_dict, fname)

Given a dictionary of refinement levels, pack it up and save it to a numpy file. FIXME: This can’t yet distinguish the level of refinement. Need to teach it to pay attention to the resolution.

RIFT.misc.amrlib.transform_chi_eff_chi_a_s1zs2z(mass1, mass2, chi_eff, chi_a)

Returns spin1z.

RIFT.misc.amrlib.transform_m1m2_mcdelta(m1, m2)
RIFT.misc.amrlib.transform_m1m2_mceta(m1, m2)
RIFT.misc.amrlib.transform_m1m2_mcq(m1, m2)
RIFT.misc.amrlib.transform_m1m2_tau0tau3(m1, m2, flow=40.0)
RIFT.misc.amrlib.transform_mcdelta_m1m2(mc, delta)
RIFT.misc.amrlib.transform_mceta_m1m2(mc, eta)
RIFT.misc.amrlib.transform_mcq_m1m2(mc, q)
RIFT.misc.amrlib.transform_s1zs2z_chi(m1, m2, s1z, s2z)
RIFT.misc.amrlib.transform_s1zs2z_chi_eff_chi_a(mass1, mass2, spin1z, spin2z)

Returns the aligned mass-weighted spin difference from mass1, mass2, spin1z, and spin2z.

RIFT.misc.amrlib.transform_tau0tau3_m1m2(tau0, tau3, flow=40.0)
RIFT.misc.amrlib.unpack_grid_cells(npy_cells)

Unpack the cell centers (grid points), the cell collection is returned.

Bounded KDE

class RIFT.misc.bounded_kde.BoundedKDE(pts, low=-inf, high=inf, periodic=False, bw_method=None)

Bases: gaussian_kde

Density estimation using a KDE on bounded domains. Bounds can be any combination of low or high (if no bound, set to float('inf') or float('-inf')), and can be periodic or non-periodic. Cannot handle topologies that have multi-dimensional periodicities; will only handle topologies that are direct products of (arbitrary numbers of) R, [0,1], and S1. :param pts:

(Ndim, Npts) shaped array of points (as in gaussian_kde).

Parameters:
  • low – Lower bounds; if None, assume no lower bounds.

  • high – Upper bounds; if None, assume no upper bounds.

  • periodic – Boolean array giving periodicity in each dimension; if None assume no dimension is periodic.

  • bw_method – (optional) Bandwidth estimation method (see gaussian_kde).

evaluate(pts)

Evaluate the KDE at the given points.

quantile(pt)

Quantile of pt, evaluated by a greedy algorithm. :param pt:

The point at which the quantile value is to be computed.

The quantile of pt is the fraction of points used to construct the KDE that have a lower KDE density than pt.

class RIFT.misc.bounded_kde.BoundedKDE_2d(pts, xlow=None, xhigh=None, ylow=None, yhigh=None, *args, **kwargs)

Bases: gaussian_kde

Represents a two-dimensional Gaussian kernel density estimator for a probability distribution function that exists on a bounded domain.

evaluate(pts)

Return an estimate of the density evaluated at the given points.

property xhigh

The upper bound of the x domain.

property xlow

The lower bound of the x domain.

property yhigh

The upper bound of the y domain.

property ylow

The lower bound of the y domain.

Corner Plot Utilities

RIFT.misc.our_corner.corner(xs, bins=20, range=None, weights=None, color='k', smooth=None, smooth1d=None, no_1d=True, labels=None, label_kwargs=None, show_titles=False, title_fmt='.2f', title_kwargs=None, truths=None, truth_color='#4682b4', scale_hist=False, quantiles=None, verbose=False, fig=None, max_n_ticks=5, top_ticks=False, use_math_text=False, reverse=False, hist_kwargs=None, **hist2d_kwargs)

Make a sick corner plot showing the projections of a data set in a multi-dimensional space. kwargs are passed to hist2d() or used for matplotlib styling. Parameters ———- xs : array_like[nsamples, ndim]

The samples. This should be a 1- or 2-dimensional array. For a 1-D array this results in a simple histogram. For a 2-D array, the zeroth axis is the list of samples and the next axis are the dimensions of the space.

binsint or array_like[ndim,]

The number of bins to use in histograms, either as a fixed value for all dimensions, or as a list of integers for each dimension.

weightsarray_like[nsamples,]

The weight of each sample. If None (default), samples are given equal weight.

colorstr

A matplotlib style color for all histograms.

smooth, smooth1dfloat

The standard deviation for Gaussian kernel passed to scipy.ndimage.gaussian_filter to smooth the 2-D and 1-D histograms respectively. If None (default), no smoothing is applied.

labelsiterable (ndim,)

A list of names for the dimensions. If a xs is a pandas.DataFrame, labels will default to column names.

label_kwargsdict

Any extra keyword arguments to send to the set_xlabel and set_ylabel methods.

show_titlesbool

Displays a title above each 1-D histogram showing the 0.5 quantile with the upper and lower errors supplied by the quantiles argument.

title_fmtstring

The format string for the quantiles given in titles. If you explicitly set show_titles=True and title_fmt=None, the labels will be shown as the titles. (default: .2f)

title_kwargsdict

Any extra keyword arguments to send to the set_title command.

rangeiterable (ndim,)

A list where each element is either a length 2 tuple containing lower and upper bounds or a float in range (0., 1.) giving the fraction of samples to include in bounds, e.g., [(0.,10.), (1.,5), 0.999, etc.]. If a fraction, the bounds are chosen to be equal-tailed.

truthsiterable (ndim,)

A list of reference values to indicate on the plots. Individual values can be omitted by using None.

truth_colorstr

A matplotlib style color for the truths makers.

scale_histbool

Should the 1-D histograms be scaled in such a way that the zero line is visible?

quantilesiterable

A list of fractional quantiles to show on the 1-D histograms as vertical dashed lines.

verbosebool

If true, print the values of the computed quantiles.

plot_contoursbool

Draw contours for dense regions of the plot.

use_math_textbool

If true, then axis tick labels for very large or small exponents will be displayed as powers of 10 rather than using e.

reversebool

If true, plot the corner plot starting in the upper-right corner instead of the usual bottom-left corner

max_n_ticks: int

Maximum number of ticks to try to use

top_ticksbool

If true, label the top ticks of each axis

figmatplotlib.Figure

Overplot onto the provided figure object.

hist_kwargsdict

Any extra keyword arguments to send to the 1-D histogram plots.

**hist2d_kwargs

Any remaining keyword arguments are sent to corner.hist2d to generate the 2-D histogram plots.

RIFT.misc.our_corner.hist2d(x, y, bins=20, range=None, weights=None, levels=None, smooth=None, ax=None, color=None, plot_datapoints=True, plot_density=True, plot_contours=True, no_fill_contours=False, fill_contours=False, contour_kwargs=None, contourf_kwargs=None, data_kwargs=None, **kwargs)

Plot a 2-D histogram of samples. Parameters ———- x : array_like[nsamples,]

The samples.

yarray_like[nsamples,]

The samples.

levelsarray_like

The contour levels to draw.

axmatplotlib.Axes

A axes instance on which to add the 2-D histogram.

plot_datapointsbool

Draw the individual data points.

plot_densitybool

Draw the density colormap.

plot_contoursbool

Draw the contours.

no_fill_contoursbool

Add no filling at all to the contours (unlike setting fill_contours=False, which still adds a white fill at the densest points).

fill_contoursbool

Fill the contours.

contour_kwargsdict

Any additional keyword arguments to pass to the contour method.

contourf_kwargsdict

Any additional keyword arguments to pass to the contourf method.

data_kwargsdict

Any additional keyword arguments to pass to the plot method when adding the individual data points.

RIFT.misc.our_corner.quantile(x, q, weights=None)

Compute sample quantiles with support for weighted samples. Note —- When weights is None, this method simply calls numpy’s percentile function with the values of q multiplied by 100. Parameters ———- x : array_like[nsamples,]

The samples.

qarray_like[nquantiles,]

The list of quantiles to compute. These should all be in the range [0, 1].

weightsOptional[array_like[nsamples,]]

An optional weight corresponding to each sample. These

Returns

quantilesarray_like[nquantiles,]

The sample quantiles computed at q.

Raises

ValueError

For invalid quantiles; q not in [0, 1] or dimension mismatch between x and weights.

Reference Samples

class RIFT.misc.reference_samples.ReferenceSamples(fname=None)

Bases: object

from_ascii(fname=None, reference_params=None, npts_out=None)
from_sim_xml(fname=None, reference_params=None, npts_out=None)
from_skymap_fits(fname=None, reference_params=None, npts_out=None, cos_dec=False)

Module Utilities

class RIFT.misc.modules.Injection(e, ei)

Bases: object

RIFT.misc.modules.check_switch_m1m2s1s2(intr_prm)
RIFT.misc.modules.construct_event_time_string(t_s, t_ns)
RIFT.misc.modules.convert_cfg_section_to_cmd_line(cfg, cfg_section)
RIFT.misc.modules.convert_dict_string_to_dict(input_dict_string)
RIFT.misc.modules.convert_dict_to_cmd_line(cmds_dict)
RIFT.misc.modules.convert_injections_txt_to_objects(inj_file)
RIFT.misc.modules.convert_list_string_to_dict(list_string)
RIFT.misc.modules.convert_section_args_to_dict(cfg, section)
RIFT.misc.modules.correct_list_string_formatting(list_string)
RIFT.misc.modules.get_html_str(plot_name_no_path)
RIFT.misc.modules.get_m1m2_from_mceta(Mc, eta)
RIFT.misc.modules.get_mchirp_eta(m1, m2)
RIFT.misc.modules.get_priors(param, val, prior_limits={})
RIFT.misc.modules.html_newline()
RIFT.misc.modules.norm_sym_ratio(eta)
RIFT.misc.modules.run_cmd(cmd, verbose=1)
RIFT.misc.modules.transform_chi_eff_chi_a_s1zs2z(mass1, mass2, chi_eff, chi_a)

Returns spin1z.

RIFT.misc.modules.transform_s1zs2z_chi(m1, m2, s1z, s2z)
RIFT.misc.modules.transform_s1zs2z_chi_eff_chi_a(mass1, mass2, spin1z, spin2z)

Returns the aligned mass-weighted spin difference from mass1, mass2, spin1z, and spin2z.

RIFT.misc.modules.uniform_samp_prior(a, b, x)

DAG Utilities

A collection of routines to manage Condor workflows (DAGs).

RIFT.misc.dag_utils.bilby_ish_string_to_dict(my_str)
RIFT.misc.dag_utils.bilby_prior_dict_string_from_mc_q(mc_range, dmax_Mpc)
RIFT.misc.dag_utils.build_resolved_env(my_str)
RIFT.misc.dag_utils.generate_job_id()

Generate a unique md5 hash for use as a job ID. Borrowed and modified from the LAL code in glue/glue/pipeline.py

RIFT.misc.dag_utils.ile_gpu_fanout_value()

Launcher directive baked into ile_pre.sh, resolved from RIFT_ILE_GPU_FANOUT at DAG-build time. Recognised values (see ile_gpu_request for the matching condor request):

‘1’ / ‘single’ / ‘off’ -> no fan-out, single-GPU run (the fallback) ‘all’ (DEFAULT) -> split across EVERY physical GPU (ignore CVD; whole node) N (int) -> split the granted GPUs into <=N shards ‘auto’ -> split across exactly the GPUs condor granted (CUDA_VISIBLE_DEVICES) ‘auto-max-N’ -> adaptive (partitionable slots): condor grants 1..N GPUs;

launcher splits across the granted set, so baked value is ‘auto’.

RIFT.misc.dag_utils.ile_gpu_request()

Resolve RIFT_ILE_GPU_FANOUT into the condor (request_gpus, request_cpus) values for an ILE job. Each is an int (fixed count) OR a string ClassAd expression (adaptive). Returns (1, 1) for the default ‘all’ and for ‘auto’/’off’ (those keep request_GPUs=1 – ‘all’/’auto’ obtain their GPUs at runtime from a node you have reserved; the request cannot size them ahead of time).

‘auto-max-N’ emits an expression that requests up to N of the capability-matching GPUs actually available on the matched (partitionable) slot. Override the expression with RIFT_ILE_GPU_REQUEST_EXPR if your pool exposes GPU counts differently (verify the attribute with condor_status -long <gpu-node>). Partitionable GPU slots are not the recommended path; ‘all’ is the default instead.

RIFT.misc.dag_utils.ile_invocation_shell(exe, fanout=None)

Return the shell snippet that invokes the ILE executable exe with multi-GPU fan-out (see RIFT_ILE_GPU_FANOUT). The launcher reads its source from stdin via a quoted here-doc, so the ILE arguments in “$@” (which include nested-quoted values) are passed through untouched. With fan-out disabled the launcher simply exec()s the binary, so default behaviour is unchanged.

The build-time fan-out value is BAKED into ile_pre.sh as the runtime default (still overridable by a runtime RIFT_ILE_GPU_FANOUT), so the job does NOT depend on the submit/execute environment propagating the variable – this is what makes the feature work under asimov, whose blueprints can only set the value at DAG-build time.

RIFT.misc.dag_utils.is_exe(fpath)
RIFT.misc.dag_utils.match_expr(my_list, my_expr)
RIFT.misc.dag_utils.mkdir(dir_name)
RIFT.misc.dag_utils.which(program)
RIFT.misc.dag_utils.write_1dpos_plot_sub(tag='1d_post_plot', exe=None, log_dir=None, output_dir='./')

Write a submit file for launching jobs to coalesce ILE output

RIFT.misc.dag_utils.write_CIP_single_iteration_subdag(cip_worker_job, it, unique_postfix, subdag_dir, n_retries=3, n_explode=1)
RIFT.misc.dag_utils.write_CIP_sub(tag='integrate', exe=None, input_net='all.net', output='output-ILE-samples', universe='vanilla', out_dir=None, log_dir=None, use_eos=False, ncopies=1, arg_str=None, request_memory=8192, request_memory_flex=False, request_gpus=0, require_gpus=None, arg_vals=None, no_grid=False, request_disk=False, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, use_oauth_files=False, use_simple_osg_requirements=False, singularity_image=None, max_runtime_minutes=None, condor_commands=None, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over intrinsic parameters.

Inputs: Outputs:

  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_ILE_sub_simple(tag='integrate', exe=None, log_dir=None, use_eos=False, simple_unique=False, ncopies=1, arg_str=None, request_memory=4096, request_gpu=False, request_cross_platform=False, request_disk=False, arg_vals=None, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, use_simple_osg_requirements=False, singularity_image=None, use_cvmfs_frames=False, use_oauth_files=False, frames_dir=None, cache_file=None, fragile_hold=False, max_runtime_minutes=None, condor_commands=None, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over intrinsic parameters.

Inputs: Outputs:

  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_bilby_pickle_sub(tag='Bilby_pickle', exe=None, universe='local', log_dir=None, ncopies=1, request_memory=4096, bilby_ini_file=None, no_grid=False, frames_dir=None, cache_file=None, ile_args=None, **kwargs)

Write a submit file for launching a job to generate a pickle file based off a bilby ini file; needed for reweight final posterior samples due to calibration uncertainty

Inputs:
  • bilby ini file

Outputs:
  • pickle file of event settings; needed as input for calibration reweighting

Notes:
  • local universe is generally safer: we need access to frame files in a standard location (typically datafind returns cvmfs, etc). That may not be available on remote nodes.

RIFT.misc.dag_utils.write_calibration_uncertainty_reweighting_sub(tag='Calib_reweight', exe=None, log_dir=None, ncopies=1, request_memory=8192, time_marg=True, pickle_file=None, posterior_file=None, universe='vanilla', no_grid=False, ile_args=None, n_cal=100, use_osg=False, use_oauth_files=False, use_singularity=False, singularity_image=None, transfer_files=None, **kwargs)

Write a submit file for launching jobs to reweight final posterior samples due to calibration uncertainty

Inputs:
  • posterior samples, event pickle file (generated by Bilby)

Outputs:
  • reweighted samples due to calibration uncertainty and corresponding weights

RIFT.misc.dag_utils.write_calpilot_sub(tag='calpilot', exe=None, log_dir=None, universe='vanilla', working_directory=None, ile_args_file=None, top_fraction=0.05, max_points=32, request_memory=4096, request_gpu=True, use_singularity=False, singularity_image=None, use_oauth_files=False, transfer_files=None, max_runtime_minutes=300, **kwargs)

Submit file for a calibration PILOT stage (Option C; see RIFT/calmarg/DESIGN_adaptive_driver.md): harvest top-lnL points from iteration $(macroiteration)’s composite, run ILE –calibration-dump-responsibilities on them, fit + consolidate a cal proposal that seeds wide_{N+1}. Runs util_CalPilotStage.py.

Macros expected at instantiation: macroiteration, macroiterationprev. Produces <wd>/cal_consolidated_$(macroiteration).npz (consumed by wide_{N+1} ILE via –calibration-proposal-breadcrumb).

RIFT.misc.dag_utils.write_cat_sub(tag='cat', exe=None, file_prefix=None, file_postfix=None, file_output=None, universe='vanilla', arg_str='', log_dir=None, use_eos=False, ncopies=1, no_grid=False, **kwargs)
Write a submit file for launching a ‘resample’ job

util_ResampleILEOutputWithExtrinsic.py

RIFT.misc.dag_utils.write_comov_distance_reweighting_sub(tag='Comov_dist', comov_distance_reweighting_exe=None, reweight_location=None, universe='vanilla', log_dir=None, ncopies=1, request_memory=4096, posterior_file=None, no_grid=False, **kwargs)

Write a submit file for launching a job to generate reweight posterior samples to reflect a comoving distance prior

Inputs:
  • posterior samples in h5 format

Outputs:
  • reweighted samples in h5 format

RIFT.misc.dag_utils.write_consolidate_sub_simple(tag='consolidate', exe=None, base=None, target=None, universe='vanilla', arg_str=None, log_dir=None, use_eos=False, ncopies=1, no_grid=False, max_runtime_minutes=120, extra_text='', **kwargs)
Write a submit file for launching a consolidation job

util_ILEdagPostprocess.sh # suitable for ILE consolidation. arg_str # add argument (used for NR postprocessing, to identify group)

RIFT.misc.dag_utils.write_convert_ascii_to_h5_sub(tag='Convert_ascii2h5', convert_ascii_to_h5_exe=None, output_file=None, universe='vanilla', log_dir=None, ncopies=1, request_memory=4096, posterior_file=None, no_grid=False, **kwargs)

Converts posterior samples file from ascii to h5 format

Inputs:
  • posterior samples in ascii format

Outputs:
  • posterior samples in h5 format

RIFT.misc.dag_utils.write_convert_sub(tag='convert', exe=None, file_input=None, file_output=None, universe='vanilla', arg_str='', log_dir=None, use_eos=False, ncopies=1, no_grid=False, max_runtime_minutes=120, **kwargs)
Write a submit file for launching a ‘convert’ job

convert_output_format_ile2inference

RIFT.misc.dag_utils.write_convertpsd_sub(tag='convert_psd', exe=None, ifo=None, file_input=None, target_dir=None, arg_str='', log_dir=None, universe='local', **kwargs)

Write script to convert PSD from one format to another. Needs to be called once per PSD file being used.

RIFT.misc.dag_utils.write_hyperpost_sub(tag='HYPER', exe=None, input_net='all.marg_net', output='output-samples', universe='vanilla', out_dir=None, log_dir=None, ncopies=1, arg_str=None, request_memory=8192, arg_vals=None, no_grid=False, request_disk=False, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, use_simple_osg_requirements=False, singularity_image=None, max_runtime_minutes=None, condor_commands=None, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over hyperparameters. Almost identical to CIP

Inputs: Outputs:

  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_init_sub(tag='gridinit', exe=None, arg_str=None, log_dir=None, use_eos=False, ncopies=1, **kwargs)

Write a submit file for launching a grid initialization job. Note this routine MUST create whatever files are needed by the ILE iteration

RIFT.misc.dag_utils.write_integrate_likelihood_extrinsic_grid_sub(tag='integrate', exe=None, log_dir=None, ncopies=1, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over extrinsic parameters. Like the other case (below), but modified to use the sim_xml and loop over ‘event’

Inputs:
  • ‘tag’ is a string to specify the base name of output files. The output submit file will be named tag.sub, and the jobs will write their output to tag-ID.out, tag-ID.err, tag.log, where ‘ID’ is a unique identifier for each instance of a job run from the sub file.

  • ‘cache’ is the path to a cache file which gives the location of the data to be analyzed.

  • ‘sim’ is the path to the XML file with the grid

  • ‘channelH1/L1/V1’ is the channel name to be read for each of the H1, L1 and V1 detectors.

  • ‘psdH1/L1/V1’ is the path to an XML file specifying the PSD of each of the H1, L1, V1 detectors.

  • ‘ncopies’ is the number of runs with identical input parameters to submit per condor ‘cluster’

Outputs:
  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_integrate_likelihood_extrinsic_sub(tag='integrate', exe=None, log_dir=None, ncopies=1, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over extrinsic parameters.

Inputs:
  • ‘tag’ is a string to specify the base name of output files. The output submit file will be named tag.sub, and the jobs will write their output to tag-ID.out, tag-ID.err, tag.log, where ‘ID’ is a unique identifier for each instance of a job run from the sub file.

  • ‘cache’ is the path to a cache file which gives the location of the data to be analyzed.

  • ‘coinc’ is the path to a coincident XML file, from which masses and times will be drawn FIXME: remove this once it’s no longer needed.

  • ‘channelH1/L1/V1’ is the channel name to be read for each of the H1, L1 and V1 detectors.

  • ‘psdH1/L1/V1’ is the path to an XML file specifying the PSD of each of the H1, L1, V1 detectors.

  • ‘ncopies’ is the number of runs with identical input parameters to submit per condor ‘cluster’

Outputs:
  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_joingrids_sub(tag='join_grids', exe=None, universe='vanilla', input_pattern=None, target_dir=None, output_base=None, log_dir=None, n_explode=1, gzip='/usr/bin/gzip', old_add=False, old_style_add=False, no_grid=False, extra_text='', **kwargs)

Write script to merge CIP ‘overlap-grid-(iteration)-*.xml.gz results. Issue is that

RIFT.misc.dag_utils.write_plot_sub(tag='converge', exe=None, samples_files=None, base=None, target=None, arg_str=None, log_dir=None, use_eos=False, ncopies=1, **kwargs)

Write a submit file for launching a final plot. Note the user can in principle specify several samples (e.g., several iterations, if we want to diagnose them)

RIFT.misc.dag_utils.write_posterior_plot_sub(tag='plot_post', exe=None, log_dir=None, output_dir='./')

Write a submit file for launching jobs to coalesce ILE output

RIFT.misc.dag_utils.write_psd_sub_BW_monoblock(tag='PSD_BW_mono', exe=None, log_dir=None, ncopies=1, arg_str=None, request_memory=4096, arg_vals=None, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, singularity_image=None, frames_dir=None, cache_file=None, psd_length=4, srate=4096, data_start_time=None, event_time=None, universe='local', no_grid=False, **kwargs)

Write a submit file for constructing the PSD using BW Modern argument syntax for BW Note that all ifo-specific results must be set outside this loop, to work sensibly, and passed as an argument

Inputs:
  • channel_dict[‘H1’] = [channel_name, flow_ifo]

Outputs:
  • An instance of the CondorDAGJob that was generated for BW

RIFT.misc.dag_utils.write_psd_sub_BW_step0(tag='PSD_BW', exe=None, log_dir=None, ncopies=1, arg_str=None, request_memory=4096, arg_vals=None, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, singularity_image=None, frames_dir=None, cache_file=None, channel_dict=None, psd_length=4, srate=4096, data_start_time=None, event_time=None, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over intrinsic parameters.

Inputs:
  • channel_dict[‘H1’] = [channel_name, flow_ifo]

Outputs:
  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_psd_sub_BW_step1(tag='PSD_BW_post', exe=None, log_dir=None, ncopies=1, arg_str=None, request_memory=4096, arg_vals=None, transfer_files=None, transfer_output_files=None, use_singularity=False, use_osg=False, singularity_image=None, frames_dir=None, cache_file=None, channel_dict=None, psd_length=4, srate=4096, data_start_time=None, event_time=None, **kwargs)

Write a submit file for launching jobs to marginalize the likelihood over intrinsic parameters.

Inputs:
  • channel_dict[‘H1’] = [channel_name, flow_ifo]

Outputs:
  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_puff_sub(tag='puffball', exe=None, base=None, input_net='output-ILE-samples', output='puffball', universe='vanilla', out_dir=None, log_dir=None, use_eos=False, ncopies=1, arg_str=None, request_memory=1024, arg_vals=None, no_grid=False, extra_text='', **kwargs)

Perform puffball calculation Inputs: Outputs:

  • An instance of the CondorDAGJob that was generated for ILE

RIFT.misc.dag_utils.write_refine_sub(tag='refine', exe=None, input_net=None, input_grid=None, output=None, universe='vanilla', out_dir=None, log_dir=None, use_eos=False, ncopies=1, arg_str=None, request_memory=1024, arg_vals=None, target=None, no_grid=False, **kwargs)

Write a submit file for creating a refined CIP grid for NR-based runs.

RIFT.misc.dag_utils.write_resample_sub(tag='resample', exe=None, file_input=None, file_output=None, universe='vanilla', arg_str='', log_dir=None, use_eos=False, ncopies=1, no_grid=False, **kwargs)
Write a submit file for launching a ‘resample’ job

util_ResampleILEOutputWithExtrinsic.py

RIFT.misc.dag_utils.write_result_coalescence_sub(tag='coalesce', exe=None, log_dir=None, output_dir='./', use_default_cache=True)

Write a submit file for launching jobs to coalesce ILE output

RIFT.misc.dag_utils.write_subdagILE_sub(tag='subdag_ile', full_path_name=True, exe=None, universe='vanilla', submit_file=None, input_pattern=None, target_dir=None, output_suffix=None, log_dir=None, sim_xml=None, **kwargs)

Write script to convert PSD from one format to another. Needs to be called once per PSD file being used.

RIFT.misc.dag_utils.write_test_sub(tag='converge', exe=None, samples_files=None, base=None, target=None, universe='target', arg_str=None, log_dir=None, use_eos=False, ncopies=1, no_grid=False, **kwargs)

Write a submit file for launching a convergence test job

RIFT.misc.dag_utils.write_tri_plot_sub(tag='plot_tri', injection_file=None, exe=None, log_dir=None, output_dir='./')

Write a submit file for launching jobs to coalesce ILE output

RIFT.misc.dag_utils.write_unify_sub_simple(tag='unify', exe=None, base=None, target=None, universe='vanilla', arg_str=None, log_dir=None, use_eos=False, ncopies=1, no_grid=False, max_runtime_minutes=60, extra_text='', **kwargs)
Write a submit file for launching a consolidation job

util_ILEdagPostprocess.sh # suitable for ILE consolidation. arg_str # add argument (used for NR postprocessing, to identify group)

Samples Utilities

RIFT.misc.samples_utils.add_field(a, descr)

Returns a new structured array with additional fields.

The contents of “a” are copied over to the appropriate fields in the new array, while the new fields are left uninitialized. The original array “a” is not modified.

Args:

a (np.ndarray): A structured numpy array. descr (list): A numpy type description of the new fields to add

(e.g., [(‘field_name’, float)]).

Returns:

np.ndarray: A new structured array containing the original fields and the new fields.

Raises:

ValueError: If the input array a is not a structured numpy array.

RIFT.misc.samples_utils.alt_expand_samples(samples)

Llike standard_expand_samples, but targeted specifically for composite files

RIFT.misc.samples_utils.dump_pesummary_samples_to_file_as_rift(fname_h5, key, fname_out, no_drop=False, no_rename=False)

Converts posterior samples from a pesummary HDF5 file to the RIFT text format.

Reads samples from the specified key in the HDF5 file, renames fields based on remap_bilby_to_rift, and optionally drops metadata fields (e.g., SNR, recalib).

Args:

fname_h5 (str): Path to the input pesummary HDF5 file. key (str): The key within the HDF5 file where the samples are stored. fname_out (str): Path to the output text file. no_drop (bool, optional): If True, does not drop ‘recalib’ or ‘snr’ fields. Defaults to False. no_rename (bool, optional): If True, does not rename fields using remap_bilby_to_rift. Defaults to False.

Raises:

Exception: If the provided key is not found in the HDF5 file.

Example:
>>> import samples_utils
>>> samples_utils.dump_pesummary_samples_to_file_as_rift("metafile.h5", "bilby-IMRPhenomXPHM-SpinTaylor-3",'test.dat')

$ convert_output_format_inference2ile –posterior-samples test.dat –output-xml my.xml.gz

RIFT.misc.samples_utils.extract_combination_from_LI(samples_LI, p)

Extracts a specific parameter or computed combination from posterior samples.

This function reads known columns from the posterior samples. If the requested parameter p is not directly available, it attempts to compute it from standard quantities using predefined remapping and physics formulas (e.g., computing effective spin chi_eff from individual spin components).

Args:

samples_LI (np.recarray): A structured numpy array containing posterior samples. p (str): The name of the parameter or combination to extract.

Returns:
np.ndarray: An array containing the extracted or computed values for parameter p.

Returns an array of zeros if the parameter cannot be accessed to avoid hard failures.

RIFT.misc.samples_utils.fchip(sample)

Helper function to compute the effective spin chi_p for a single sample.

Designed for use with multiprocessing.Pool.map.

Args:

sample (tuple): A tuple containing [m1, m2, s1x, s1y, s1z, s2x, s2y, s2z].

Returns:

float: The computed chi_p value.

RIFT.misc.samples_utils.fchipavg(sample)

Helper function to compute the average effective spin chi_pavg for a single sample.

Designed for use with multiprocessing.Pool.map.

Args:

sample (tuple): A tuple containing [m1, m2, s1x, s1y, s1z, s2x, s2y, s2z].

Returns:

float: The computed chi_pavg value.

RIFT.misc.samples_utils.standard_expand_samples(samples)

Expands a sample set by adding standard derived parameters.

This function checks for the presence of certain base parameters and computes derived quantities if they are missing. This is commonly used for preparing samples for plotting (e.g., in plot_posterior_corner.py).

Added fields may include: - Mass parameters: mtotal, eta, m1, m2 (computed from mc and q). - Spin parameters: a1x, a1y, a2x, a2y, chi1_perp, chi2_perp, chi_eff

(computed from a1, theta1, phi1, etc.).

  • Angles: phi1, phi2, phi12.

  • Tidal parameters: lambdat, dlambdat (computed from lambda1, lambda2).

Args:

samples (np.recarray): A structured numpy array of posterior samples.

Returns:

np.recarray: The expanded structured array containing the original and derived fields.

Modified Scikit Fit

class RIFT.misc.ModifiedScikitFit.Binarizer(threshold=0.0, copy=True)

Bases: BaseEstimator, TransformerMixin

Binarize data (set feature values to 0 or 1) according to a threshold Values greater than the threshold map to 1, while values less than or equal to the threshold map to 0. With the default threshold of 0, only positive values map to 1. Binarization is a common operation on text count data where the analyst can decide to only consider the presence or absence of a feature rather than a quantified number of occurrences for instance. It can also be used as a pre-processing step for estimators that consider boolean random variables (e.g. modelled using the Bernoulli distribution in a Bayesian setting). Read more in the User Guide. Parameters ———- threshold : float, optional (0.0 by default)

Feature values below or equal to this are replaced by 0, above it by 1. Threshold may not be less than 0 for operations on sparse matrices.

copyboolean, optional, default True

set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix).

Notes

If the input is a sparse matrix, only the non-zero values are subject to update by the Binarizer class. This estimator is stateless (besides constructor parameters), the fit method does nothing but is useful when used in a pipeline. See also ——– binarize: Equivalent function without the object oriented API.

fit(X, y=None)

Do nothing and return the estimator unchanged This method is just there to implement the usual API and hence work in pipelines.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → Binarizer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(X, y=None, copy=None)

Binarize each element of X Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to binarize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

class RIFT.misc.ModifiedScikitFit.KernelCenterer

Bases: BaseEstimator, TransformerMixin

Center a kernel matrix Let K(x, z) be a kernel defined by phi(x)^T phi(z), where phi is a function mapping x to a Hilbert space. KernelCenterer centers (i.e., normalize to have zero mean) the data without explicitly computing phi(x). It is equivalent to centering phi(x) with sklearn.preprocessing.StandardScaler(with_std=False). Read more in the User Guide.

fit(K, y=None)

Fit KernelCenterer Parameters ———- K : numpy array of shape [n_samples, n_samples]

Kernel matrix.

Returns

self : returns an instance of self.

set_fit_request(*, K: bool | None | str = '$UNCHANGED$') → KernelCenterer

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

Kstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for K parameter in fit.

Returns

selfobject

The updated object.

set_transform_request(*, K: bool | None | str = '$UNCHANGED$', copy: bool | None | str = '$UNCHANGED$') → KernelCenterer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

Kstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for K parameter in transform.

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(K, y=None, copy=True)

Center kernel matrix. Parameters ———- K : numpy array of shape [n_samples1, n_samples2]

Kernel matrix.

copyboolean, optional, default True

Set to False to perform inplace computation.

Returns

K_new : numpy array of shape [n_samples1, n_samples2]

class RIFT.misc.ModifiedScikitFit.MaxAbsScaler(copy=True)

Bases: BaseEstimator, TransformerMixin

Scale each feature by its maximum absolute value. This estimator scales and translates each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity. This scaler can also be applied to sparse CSR or CSC matrices. .. versionadded:: 0.17 Parameters ———- copy : boolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

Attributes

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ attribute.

max_abs_ndarray, shape (n_features,)

Per feature maximum absolute value.

n_samples_seen_int

The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across partial_fit calls.

See also

maxabs_scale: Equivalent function without the object oriented API.

fit(X, y=None)

Compute the maximum absolute value to be used for later scaling. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.

inverse_transform(X)

Scale back the data to the original representation Parameters ———- X : {array-like, sparse matrix}

The data that should be transformed back.

partial_fit(X, y=None)

Online computation of max absolute value of X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

transform(X, y=None)

Scale the data Parameters ———- X : {array-like, sparse matrix}

The data that should be scaled.

class RIFT.misc.ModifiedScikitFit.MinMaxScaler(feature_range=(0, 1), copy=True)

Bases: BaseEstimator, TransformerMixin

Transforms features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by:

X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min

where min, max = feature_range. This transformation is often used as an alternative to zero mean, unit variance scaling. Read more in the User Guide. Parameters ———- feature_range : tuple (min, max), default=(0, 1)

Desired range of transformed data.

copyboolean, optional, default True

Set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array).

Attributes

min_ndarray, shape (n_features,)

Per feature adjustment for minimum.

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ attribute.

data_min_ndarray, shape (n_features,)

Per feature minimum seen in the data .. versionadded:: 0.17

data_min_ instead of deprecated data_min.

data_max_ndarray, shape (n_features,)

Per feature maximum seen in the data .. versionadded:: 0.17

data_max_ instead of deprecated data_max.

data_range_ndarray, shape (n_features,)

Per feature range (data_max_ - data_min_) seen in the data .. versionadded:: 0.17

data_range_ instead of deprecated data_range.

See also

minmax_scale: Equivalent function without the object oriented API.

property data_min
property data_range
fit(X, y=None)

Compute the minimum and maximum to be used for later scaling. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the per-feature minimum and maximum used for later scaling along the features axis.

inverse_transform(X)

Undo the scaling of X according to feature_range. Parameters ———- X : array-like, shape [n_samples, n_features]

Input data that will be transformed. It cannot be sparse.

partial_fit(X, y=None)

Online computation of min and max on X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y : Passthrough for Pipeline compatibility.

transform(X)

Scaling features of X according to feature_range. Parameters ———- X : array-like, shape [n_samples, n_features]

Input data that will be transformed.

class RIFT.misc.ModifiedScikitFit.Normalizer(norm='l2', copy=True)

Bases: BaseEstimator, TransformerMixin

Normalize samples individually to unit norm. Each sample (i.e. each row of the data matrix) with at least one non zero component is rescaled independently of other samples so that its norm (l1 or l2) equals one. This transformer is able to work both with dense numpy arrays and scipy.sparse matrix (use CSR format if you want to avoid the burden of a copy / conversion). Scaling inputs to unit norms is a common operation for text classification or clustering for instance. For instance the dot product of two l2-normalized TF-IDF vectors is the cosine similarity of the vectors and is the base similarity metric for the Vector Space Model commonly used by the Information Retrieval community. Read more in the User Guide. Parameters ———- norm : ‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default)

The norm to use to normalize each non zero sample.

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix).

Notes

This estimator is stateless (besides constructor parameters), the fit method does nothing but is useful when used in a pipeline. See also ——– normalize: Equivalent function without the object oriented API.

fit(X, y=None)

Do nothing and return the estimator unchanged This method is just there to implement the usual API and hence work in pipelines.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → Normalizer

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

transform(X, y=None, copy=None)

Scale each non zero row of X to unit norm Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to normalize, row by row. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

class RIFT.misc.ModifiedScikitFit.OneHotEncoder(n_values='auto', categorical_features='all', dtype=<class 'numpy.float64'>, sparse=True, handle_unknown='error')

Bases: BaseEstimator, TransformerMixin

Encode categorical integer features using a one-hot aka one-of-K scheme. The input to this transformer should be a matrix of integers, denoting the values taken on by categorical (discrete) features. The output will be a sparse matrix where each column corresponds to one possible value of one feature. It is assumed that input features take on values in the range [0, n_values). This encoding is needed for feeding categorical data to many scikit-learn estimators, notably linear models and SVMs with the standard kernels. Note: a one-hot encoding of y labels should use a LabelBinarizer instead. Read more in the User Guide. Parameters ———- n_values : ‘auto’, int or array of ints

Number of values per feature. - ‘auto’ : determine value range from training data. - int : number of categorical values per feature.

Each feature value should be in range(n_values)

  • arrayn_values[i] is the number of categorical values in

    X[:, i]. Each feature value should be in range(n_values[i])

categorical_features“all” or array of indices or mask

Specify what features are treated as categorical. - ‘all’ (default): All features are treated as categorical. - array of indices: Array of categorical feature indices. - mask: Array of length n_features and with dtype=bool. Non-categorical features are always stacked to the right of the matrix.

dtypenumber type, default=np.float

Desired dtype of output.

sparseboolean, default=True

Will return sparse matrix if set True else will return an array.

handle_unknownstr, ‘error’ or ‘ignore’

Whether to raise an error or ignore if a unknown categorical feature is present during transform.

Attributes

active_features_array

Indices for active features, meaning values that actually occur in the training set. Only available when n_values is 'auto'.

feature_indices_array of shape (n_features,)

Indices to feature ranges. Feature i in the original data is mapped to features from feature_indices_[i] to feature_indices_[i+1] (and then potentially masked by active_features_ afterwards)

n_values_array of shape (n_features,)

Maximum number of values per feature.

Examples

Given a dataset with three features and two samples, we let the encoder find the maximum value per feature and transform the data to a binary one-hot encoding. >>> from sklearn.preprocessing import OneHotEncoder >>> enc = OneHotEncoder() >>> enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]]) # doctest: +ELLIPSIS OneHotEncoder(categorical_features=’all’, dtype=<… ‘numpy.float64’>,

handle_unknown=’error’, n_values=’auto’, sparse=True)

>>> enc.n_values_
array([2, 3, 4])
>>> enc.feature_indices_
array([0, 2, 5, 9])
>>> enc.transform([[0, 1, 1]]).toarray()
array([[ 1.,  0.,  0.,  1.,  0.,  0.,  1.,  0.,  0.]])
See also
--------
sklearn.feature_extraction.DictVectorizer : performs a one-hot encoding of
  dictionary items (also handles string-valued features).
sklearn.feature_extraction.FeatureHasher : performs an approximate one-hot
  encoding of dictionary items or strings.
sklearn.preprocessing.LabelBinarizer : binarizes labels in a one-vs-all
  fashion.
sklearn.preprocessing.MultiLabelBinarizer : transforms between iterable of
  iterables and a multilabel format, e.g. a (samples x classes) binary
  matrix indicating the presence of a class label.
sklearn.preprocessing.LabelEncoder : encodes labels with values between 0
  and n_classes-1.
fit(X, y=None)

Fit OneHotEncoder to X. Parameters ———- X : array-like, shape [n_samples, n_feature]

Input array of type int.

Returns

self

fit_transform(X, y=None)

Fit OneHotEncoder to X, then transform X. Equivalent to self.fit(X).transform(X), but more convenient and more efficient. See fit for the parameters, transform for the return value.

transform(X)

Transform X using one-hot encoding. Parameters ———- X : array-like, shape [n_samples, n_features]

Input array of type int.

Returns

X_outsparse matrix if sparse=True else a 2-d array, dtype=int

Transformed input.

class RIFT.misc.ModifiedScikitFit.RobustScaler(with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True)

Bases: BaseEstimator, TransformerMixin

Scale features using statistics that are robust to outliers. This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile). Centering and scaling happen independently on each feature (or each sample, depending on the axis argument) by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform method. Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results. .. versionadded:: 0.17 Read more in the User Guide. Parameters ———- with_centering : boolean, True by default

If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.

with_scalingboolean, True by default

If True, scale the data to interquartile range.

quantile_rangetuple (q_min, q_max), 0.0 < q_min < q_max < 100.0

Default: (25.0, 75.0) = (1st quantile, 3rd quantile) = IQR Quantile range used to calculate scale_. .. versionadded:: 0.18

copyboolean, optional, default is True

If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.

Attributes

center_array of floats

The median value for each feature in the training set.

scale_array of floats

The (scaled) interquartile range for each feature in the training set. .. versionadded:: 0.17

scale_ attribute.

See also

robust_scale: Equivalent function without the object oriented API. sklearn.decomposition.PCA

Further removes the linear correlation across features with ‘whiten=True’.

Notes

See examples/preprocessing/plot_robust_scaling.py for an example. https://en.wikipedia.org/wiki/Median_(statistics) https://en.wikipedia.org/wiki/Interquartile_range

fit(X, y=None)

Compute the median and quantiles to be used for scaling. Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to compute the median and quantiles used for later scaling along the features axis.

inverse_transform(X)

Scale back the data to the original representation Parameters ———- X : array-like

The data used to scale along the specified axis.

transform(X, y=None)

Center and scale the data Parameters ———- X : array-like

The data used to scale along the specified axis.

class RIFT.misc.ModifiedScikitFit.StandardScaler(copy=True, with_mean=True, with_std=True)

Bases: BaseEstimator, TransformerMixin

Standardize features by removing the mean and scaling to unit variance Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Mean and standard deviation are then stored to be used on later data using the transform method. Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual feature do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance). For instance many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the L1 and L2 regularizers of linear models) assume that all features are centered around 0 and have variance in the same order. If a feature has a variance that is orders of magnitude larger that others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected. This scaler can also be applied to sparse CSR or CSC matrices by passing with_mean=False to avoid breaking the sparsity structure of the data. Read more in the User Guide. Parameters ———- with_mean : boolean, True by default

If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.

with_stdboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

copyboolean, optional, default True

If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.

Attributes

scale_ndarray, shape (n_features,)

Per feature relative scaling of the data. .. versionadded:: 0.17

scale_ is recommended instead of deprecated std_.

mean_array of floats with shape [n_features]

The mean value for each feature in the training set.

var_array of floats with shape [n_features]

The variance for each feature in the training set. Used to compute scale_

n_samples_seen_int

The number of samples processed by the estimator. Will be reset on new calls to fit, but increments across partial_fit calls.

See also

scale: Equivalent function without the object oriented API. sklearn.decomposition.PCA

Further removes the linear correlation across features with ‘whiten=True’.

fit(X, y=None)

Compute the mean and std to be used for later scaling. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

inverse_transform(X, copy=None)

Scale back the data to the original representation Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to scale along the features axis.

partial_fit(X, y=None)

Online computation of mean and std on X for later scaling. All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream. The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247: Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data used to compute the mean and standard deviation used for later scaling along the features axis.

y: Passthrough for Pipeline compatibility.

set_inverse_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → StandardScaler

Configure whether metadata should be requested to be passed to the inverse_transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in inverse_transform.

Returns

selfobject

The updated object.

set_transform_request(*, copy: bool | None | str = '$UNCHANGED$') → StandardScaler

Configure whether metadata should be requested to be passed to the transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters

copystr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for copy parameter in transform.

Returns

selfobject

The updated object.

property std_
transform(X, y=None, copy=None)

Perform standardization by centering and scaling Parameters ———- X : array-like, shape [n_samples, n_features]

The data used to scale along the features axis.

RIFT.misc.ModifiedScikitFit.add_dummy_feature(X, value=1.0)

Augment dataset with an additional dummy feature. This is useful for fitting an intercept term with implementations which cannot otherwise fit it directly. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

Data.

valuefloat

Value to use for the dummy feature.

Returns

X{array, sparse matrix}, shape [n_samples, n_features + 1]

Same data with dummy feature added as first column.

Examples

>>> from sklearn.preprocessing import add_dummy_feature
>>> add_dummy_feature([[0, 1], [1, 0]])
array([[ 1.,  0.,  1.],
       [ 1.,  1.,  0.]])
RIFT.misc.ModifiedScikitFit.binarize(X, threshold=0.0, copy=True)

Boolean thresholding of array-like or scipy.sparse matrix Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to binarize, element by element. scipy.sparse matrices should be in CSR or CSC format to avoid an un-necessary copy.

thresholdfloat, optional (0.0 by default)

Feature values below or equal to this are replaced by 0, above it by 1. Threshold may not be less than 0 for operations on sparse matrices.

copyboolean, optional, default True

set to False to perform inplace binarization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR / CSC matrix and if axis is 1).

See also

Binarizer: Performs binarization using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.maxabs_scale(X, axis=0, copy=True)

Scale each feature to the [-1, 1] range without breaking the sparsity. This estimator scales each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. This scaler can also be applied to sparse CSR or CSC matrices. Parameters ———- axis : int (0 by default)

axis used to scale along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

copyboolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

See also

MaxAbsScaler: Performs scaling to the [-1, 1] range using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.minmax_scale(X, feature_range=(0, 1), axis=0, copy=True)

Transforms features by scaling each feature to a given range. This estimator scales and translates each feature individually such that it is in the given range on the training set, i.e. between zero and one. The transformation is given by:

X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
X_scaled = X_std * (max - min) + min

where min, max = feature_range. This transformation is often used as an alternative to zero mean, unit variance scaling. Read more in the User Guide. .. versionadded:: 0.17

minmax_scale function interface to sklearn.preprocessing.MinMaxScaler.

Parameters

feature_rangetuple (min, max), default=(0, 1)

Desired range of transformed data.

axisint (0 by default)

axis used to scale along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

copyboolean, optional, default is True

Set to False to perform inplace scaling and avoid a copy (if the input is already a numpy array).

See also

MinMaxScaler: Performs scaling to a given range using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.normalize(X, norm='l2', axis=1, copy=True, return_norm=False)

Scale input vectors individually to unit norm (vector length). Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}, shape [n_samples, n_features]

The data to normalize, element by element. scipy.sparse matrices should be in CSR format to avoid an un-necessary copy.

norm‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default)

The norm to use to normalize each non zero sample (or each non-zero feature if axis is 0).

axis0 or 1, optional (1 by default)

axis used to normalize the data along. If 1, independently normalize each sample, otherwise (if 0) normalize each feature.

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).

return_normboolean, default False

whether to return the computed norms

See also

Normalizer: Performs normalization using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.robust_scale(X, axis=0, with_centering=True, with_scaling=True, quantile_range=(25.0, 75.0), copy=True)

Standardize a dataset along any axis Center to the median and component wise scale according to the interquartile range. Read more in the User Guide. Parameters ———- X : array-like

The data to center and scale.

axisint (0 by default)

axis used to compute the medians and IQR along. If 0, independently scale each feature, otherwise (if 1) scale each sample.

with_centeringboolean, True by default

If True, center the data before scaling.

with_scalingboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

quantile_rangetuple (q_min, q_max), 0.0 < q_min < q_max < 100.0

Default: (25.0, 75.0) = (1st quantile, 3rd quantile) = IQR Quantile range used to calculate scale_. .. versionadded:: 0.18

copyboolean, optional, default is True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).

Notes

This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems. Instead the caller is expected to either set explicitly with_centering=False (in that case, only variance scaling will be performed on the features of the CSR matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory. To avoid memory copy the caller should pass a CSR matrix. See also ——– RobustScaler: Performs centering and scaling using the Transformer API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).

RIFT.misc.ModifiedScikitFit.scale(X, axis=0, with_mean=True, with_std=True, copy=True)

Standardize a dataset along any axis Center to the mean and component wise scale to unit variance. Read more in the User Guide. Parameters ———- X : {array-like, sparse matrix}

The data to center and scale.

axisint (0 by default)

axis used to compute the means and standard deviations along. If 0, independently standardize each feature, otherwise (if 1) standardize each sample.

with_meanboolean, True by default

If True, center the data before scaling.

with_stdboolean, True by default

If True, scale the data to unit variance (or equivalently, unit standard deviation).

copyboolean, optional, default True

set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSC matrix and if axis is 1).

Notes

This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems. Instead the caller is expected to either set explicitly with_mean=False (in that case, only variance scaling will be performed on the features of the CSC matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory. To avoid memory copy the caller should pass a CSC matrix. See also ——– StandardScaler: Performs scaling to unit variance using the``Transformer`` API

(e.g. as part of a preprocessing sklearn.pipeline.Pipeline).