Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr129 committed Oct 31, 2016
1 parent 8041adb commit f9f244b
Show file tree
Hide file tree
Showing 31 changed files with 1,400 additions and 1,351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override IEnumerable<Cluster> Cluster( IntensityMatrix vmatrix, Distan
{
object[] inputs =
{
_script.IsInputPresent(0) ? vmatrix.Values.Flatten() : null,
_script.IsInputPresent(0) ? vmatrix.Values : null,
_script.IsInputPresent(1) ? dmatrix.Values : null
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static bool Assign( IntensityMatrix vmatrix, IReadOnlyList<Cluster> toCho
/// Calculates the cluster with the best score for v.
/// Will not assign to insignificant, distant or disabled clusters.
/// </summary>
private static ClusterScore FindClosestCluster(double[] vector, IEnumerable<Cluster> toChoose, ConfigurationMetric distanceMetric)
private static ClusterScore FindClosestCluster(IReadOnlyList< double> vector, IEnumerable<Cluster> toChoose, ConfigurationMetric distanceMetric)
{
Cluster bestCluster = null;
double bestScore = double.NaN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override IEnumerable<Cluster> Cluster( IntensityMatrix vmatrix, Distan
throw new InvalidOperationException( $"The chosen peak {{{seedPeak}}} cannot be used a seed because it is not present in the value matrix. Please check that this peak has not been excluded by the filter condition {{{args.PeakFilter}}}.");
}

seedCluster.Exemplars.Add( vmatrix.Values[seedIndex]);
seedCluster.Exemplars.Add( vmatrix.Vectors[seedIndex]);

// Autogenerate the clusters
int? nCountLimit = (countLimit != Int32.MinValue) ? countLimit : (int?)null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static double CalculateBic(IReadOnlyList<Cluster> clusters, IReadOnlyList
{
double numClusters = clusters.Count();
double numPoints = assignments.Count;
double numDims = assignments[0].Vector.Values.Length;
double numDims = assignments[0].Vector.Values.Count;

double logLikelihood = CalculateBic_CalculateLogLikelihood(clusters, numPoints, numDims);
double numParams = CalculateBic_CalculateFreeParams(numClusters, numDims);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal void RecalculateStatistics(Core core, ConfigurationMetric metric, Inten
{
// Add basics
ClustererStatistics[STAT_NUM_VECTORS] = vmatrix.NumRows;
ClustererStatistics[STAT_LENGTH_OF_VECTORS] = vmatrix.Values[0].Length;
ClustererStatistics[STAT_LENGTH_OF_VECTORS] = vmatrix.NumCols;

// Don't calculate metrics?
if (statistics == EClustererStatistics.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override SourceTracker GetTracker()
/// <summary>
/// Like Correct(), but just gets the trend (for plots).
/// </summary>
internal double[] ExtractTrend(Core core, double[] raw, out IReadOnlyList<ObservationInfo> trendOrder)
internal double[] ExtractTrend(Core core, IReadOnlyList< double> raw, out IReadOnlyList<ObservationInfo> trendOrder)
{
if (!this.Args.IsUsingTrend)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ internal double[] ExtractTrend(Core core, double[] raw, out IReadOnlyList<Observ
{
IReadOnlyList<ObservationInfo> x = core.Observations;
IReadOnlyList<ObservationInfo> xOut = core.Observations;
double[] y = raw;
IReadOnlyList< double> y = raw;
IReadOnlyList<BatchInfo> g = core.Batches;

trendOrder = xOut;
Expand Down Expand Up @@ -86,7 +86,7 @@ internal double[] ExtractTrend(Core core, double[] raw, out IReadOnlyList<Observ
/// <summary>
/// Executes the correction for a set of raw values (in core.observation order).
/// </summary>
public double[] Calculate(Core core, double[] raw)
public double[] Calculate(Core core, IReadOnlyList< double> raw)
{
double[] result;

Expand All @@ -105,7 +105,7 @@ public double[] Calculate(Core core, double[] raw)
IReadOnlyList<ObservationInfo> trendOrder;
double[] trend = this.ExtractTrend(core, raw, out trendOrder);
IReadOnlyList<ObservationInfo> resultOrder = core.Observations;
result = new double[raw.Length];
result = new double[raw.Count];

switch (args.Mode)
{
Expand All @@ -123,7 +123,7 @@ public double[] Calculate(Core core, double[] raw)
break;

case ECorrectionMethod.Subtract:
for (int i = 0; i < raw.Length; i++)
for (int i = 0; i < raw.Count; i++)
{
result[i] = raw[i] - trend[i];
}
Expand All @@ -138,7 +138,7 @@ public double[] Calculate(Core core, double[] raw)
case ECorrectionMode.Control:
{
// Here the trend will only represent the control group
for (int i = 0; i < raw.Length; i++)
for (int i = 0; i < raw.Count; i++)
{
ObservationInfo obs = resultOrder[i];

Expand Down Expand Up @@ -181,13 +181,15 @@ protected override void OnRun( Core core, ProgressReporter prog )
{
// For each peak
IntensityMatrix source = this.Args.SourceMatrix;
double[][] results = new double[source.NumRows][];
double[,] results = new double[source.NumRows, source.NumCols];

for (int peakIndex = 0; peakIndex < source.NumRows; peakIndex++)
{
prog.SetProgress( peakIndex, source.NumRows );
Peak x = source.Rows[peakIndex].Peak;
results[peakIndex] =this.Calculate( core, source.Values[peakIndex] );
var row = this.Calculate( core, source.Vectors[peakIndex] );

ArrayHelper.CopyRow( row, results, peakIndex );
}

IntensityMatrix imresult = new IntensityMatrix( source.Rows, source.Columns, results );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CorrectionBase(string id, string name)
// NA
}

public abstract double[] Calculate(double[] raw, ArgsCorrection args);
public abstract double[] Calculate(IReadOnlyList< double> raw, ArgsCorrection args);

protected abstract override AlgoParameterCollection CreateParamaterDesription();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public CorrectionDirtyRectify(string id, string name) : base(id, name)
{
}

public override double[] Calculate(double[] raw, ArgsCorrection args)
public override double[] Calculate(IReadOnlyList< double> raw, ArgsCorrection args)
{
double c = (double)args.Parameters[0];

double[] result = new double[raw.Length];
double[] result = new double[raw.Count];

for (int index = 0; index < result.Length; index++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CorrectionScript(string script, string id, string name, string fileName)
this._script = new RScript(script, INPUT_TABLE, fileName);
}

public override double[] Calculate(double[] raw, ArgsCorrection args)
public override double[] Calculate(IReadOnlyList< double> raw, ArgsCorrection args)
{
object[] inputs = { raw };
object[] parameters = args.Parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace MetaboliteLevels.Data.Algorithms.Definitions.Metrics
[Serializable]
sealed class ConfigurationMetric : ConfigurationBase<MetricBase, ArgsMetric, ResultStatistic, SourceTracker>
{
internal double Calculate(double[] a, double[] b)
internal double Calculate(IReadOnlyList< double> a, IReadOnlyList< double> b)
{
return this.Args.GetAlgorithmOrThrow().QuickCalculate(a, b, this.Args.Parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public override double Calculate(InputStatistic input)
return _delegate(a, b);
}

public override double QuickCalculate(double[] a, double[] b, object[] parameters)
{
return _delegate(a, b);
public override double QuickCalculate(IReadOnlyList< double> a, IReadOnlyList< double> b, object[] parameters)
{
return _delegate(a.ToArray(), b.ToArray()); // TODO: Inefficient
}

protected override AlgoParameterCollection CreateParamaterDesription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MetricScript(string script, string id, string name, string fileName)
_supportsQuickCalculate = _script.CheckInputMask("1100000000");
}

public override double QuickCalculate(double[] a, double[] b, object[] args)
public override double QuickCalculate(IReadOnlyList< double> a, IReadOnlyList< double> b, object[] args)
{
UiControls.Assert(SupportsQuickCalculate, "Quick calculate called on a non quick-calculate script.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MetricBase(string id, string name)
/// Calculates the metric of the two input vectors [a] and [b].
/// This is only available if the statistic has declared [ESpecial.SupportsQuickCalculate] on its parameters.
/// </summary>
public abstract double QuickCalculate(double[] a, double[] b, object[] parameters);
public abstract double QuickCalculate(IReadOnlyList< double> a, IReadOnlyList< double> b, object[] parameters);

/// <summary>
/// OVERRIDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal sealed class ConfigurationTrend : ConfigurationBase<TrendBase, ArgsTren
public Vector CreateTrend( Core core, Vector vector )
{
double[] newValues = this.CreateTrend( vector.Observations, core.Conditions, core.Groups, vector.Values );
IntensityMatrix temporary = new IntensityMatrix( new[] { vector.Peak }, core.Conditions.ToArray(), new[] { newValues } );
IntensityMatrix temporary = new IntensityMatrix( new[] { vector.Peak }, core.Conditions.ToArray(), Vector.VectorToMatrix( newValues ) );
return temporary.Vectors[0];
}

Expand All @@ -35,7 +35,7 @@ protected override SourceTracker GetTracker()
return new SourceTracker( this.Args );
}

internal double[] CreateTrend(IReadOnlyList<ObservationInfo> inOrder, IReadOnlyList<ObservationInfo> outOrder, IReadOnlyList<GroupInfo> typeInfo, double[] raw)
internal double[] CreateTrend(IReadOnlyList<ObservationInfo> inOrder, IReadOnlyList<ObservationInfo> outOrder, IReadOnlyList<GroupInfo> typeInfo, IReadOnlyList< double> raw)
{
return this.Args.GetAlgorithmOrThrow().SmoothByType(inOrder, outOrder, typeInfo, raw, this.Args);
}
Expand All @@ -45,15 +45,22 @@ internal double[] CreateTrend(IReadOnlyList<ObservationInfo> inOrder, IReadOnlyL
protected override void OnRun( Core core, ProgressReporter prog )
{
IntensityMatrix source = this.Args.SourceMatrix;
double[][] results = new double[source.NumRows][];
double[,] results = null;

for (int index = 0; index < source.NumRows; index++)
{
prog.SetProgress( index, source.NumRows );

// Apply new trend
// TODO: Should we be using core. here?
results[index] = this.CreateTrend( core.Observations, core.Conditions, core.Groups, source.Values[index] ); // obs
// TODO: Should we be using core here?
double[] r = this.CreateTrend( core.Observations, core.Conditions, core.Groups, source.Vectors[index] ); // obs

if (results == null)
{
results = new double[source.NumRows, r.Length];
}

ArrayHelper.CopyRow( r, results, index );
}

IntensityMatrix.RowHeader[] rows = source.Rows;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public TrendBase(string id, string name)
/// <summary>
/// Smooths input data by type with x = time.
/// </summary>
internal double[] SmoothByType(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IReadOnlyList<GroupInfo> groups, double[] raw, ArgsTrend a)
internal double[] SmoothByType(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IReadOnlyList<GroupInfo> groups, IReadOnlyList< double> raw, ArgsTrend a)
{
return this.SmoothByType(inputOrder, outputOrder, groups, raw, a.Parameters);
}

/// <summary>
/// Smooths input data by type with x = time.
/// </summary>
protected double[] SmoothByType(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IReadOnlyList<GroupInfo> groups, double[] raw, object[] args)
protected double[] SmoothByType(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IReadOnlyList<GroupInfo> groups, IReadOnlyList< double> raw, object[] args)
{
double[] r = new double[outputOrder.Count];

Expand Down Expand Up @@ -76,15 +76,15 @@ protected double[] SmoothByType(IReadOnlyList<ObservationInfo> inputOrder, IRead
/// <summary>
/// Smooths data by batch with x = acquisition order.
/// </summary>
internal double[] SmoothByBatch(IReadOnlyList<ObservationInfo> x, IReadOnlyList<ObservationInfo> xOut, IEnumerable<BatchInfo> batches, double[] raw, ArgsTrend a)
internal double[] SmoothByBatch(IReadOnlyList<ObservationInfo> x, IReadOnlyList<ObservationInfo> xOut, IEnumerable<BatchInfo> batches, IReadOnlyList< double> raw, ArgsTrend a)
{
return this.SmoothByBatch(x, xOut, batches, raw, a.Parameters);
}

/// <summary>
/// Smooths data by batch with x = acquisition order.
/// </summary>
protected double[] SmoothByBatch(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IEnumerable<BatchInfo> batches, double[] raw, object[] args)
protected double[] SmoothByBatch(IReadOnlyList<ObservationInfo> inputOrder, IReadOnlyList<ObservationInfo> outputOrder, IEnumerable<BatchInfo> batches, IReadOnlyList< double> raw, object[] args)
{
double[] r = new double[outputOrder.Count];

Expand Down
2 changes: 1 addition & 1 deletion MetaboliteLevels/Data/Algorithms/General/DistanceMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static DistanceMatrix Create(Core core, IntensityMatrix valueMatrix, Conf

for (int j = 0; j < n; j++)
{
s[i, j] = metric.Calculate(valueMatrix.Values[i], valueMatrix.Values[j]);
s[i, j] = metric.Calculate(valueMatrix.Vectors[i], valueMatrix.Vectors[j]);
}
}

Expand Down
Loading

0 comments on commit f9f244b

Please sign in to comment.