Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/23/12 00:31:49 (10 years ago)
Author:
abeham
Message:

#1913: Added regularization term introduced by Yang and Laaksonen 2007

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Nca/Matrix.cs

    r8471 r8681  
    7070
    7171    public Matrix Transpose() {
    72       var result = new Matrix(Transpose(values, Columns, Rows), Columns, Rows);
    73       return result;
     72      return new Matrix(Transpose(values, Columns, Rows), Columns, Rows);
    7473    }
    7574
     
    125124    }
    126125
    127     public double VectorLength() {
    128       return Math.Sqrt(SquaredVectorLength());
    129     }
    130 
    131     public double SquaredVectorLength() {
    132       if (Rows != 1) throw new ArgumentException("Length only works on vectors.");
     126    public double EuclideanNorm() {
     127      return Math.Sqrt(SumOfSquares());
     128    }
     129
     130    public double SumOfSquares() {
    133131      return values.Sum(x => x * x);
    134132    }
     
    137135      if (Rows != 1 || other.Rows != 1) throw new ArgumentException("OuterProduct can only be applied to vectors.");
    138136      return Transpose().Multiply(other);
     137    }
     138
     139    public IEnumerable<double> ColumnSums() {
     140      return Transpose().RowSums();
     141    }
     142
     143    public IEnumerable<double> RowSums() {
     144      var sum = 0.0;
     145      int counter = 0;
     146      foreach (var v in values) {
     147        sum += v;
     148        counter++;
     149        if (counter == Rows) {
     150          yield return sum;
     151          sum = 0.0;
     152          counter = 0;
     153        }
     154      }
    139155    }
    140156
Note: See TracChangeset for help on using the changeset viewer.