本文整理汇总了C#中DoubleMatrix类的典型用法代码示例。如果您正苦于以下问题:C# DoubleMatrix类的具体用法?C# DoubleMatrix怎么用?C# DoubleMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoubleMatrix类属于命名空间,在下文中一共展示了DoubleMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyClassInitialize
public static void MyClassInitialize(TestContext testContext) {
random = new MersenneTwister();
symmetricDistances = new DoubleMatrix(ProblemSize, ProblemSize);
symmetricWeights = new DoubleMatrix(ProblemSize, ProblemSize);
asymmetricDistances = new DoubleMatrix(ProblemSize, ProblemSize);
asymmetricWeights = new DoubleMatrix(ProblemSize, ProblemSize);
nonZeroDiagonalDistances = new DoubleMatrix(ProblemSize, ProblemSize);
nonZeroDiagonalWeights = new DoubleMatrix(ProblemSize, ProblemSize);
for (int i = 0; i < ProblemSize - 1; i++) {
for (int j = i + 1; j < ProblemSize; j++) {
symmetricDistances[i, j] = random.Next(ProblemSize * 100);
symmetricDistances[j, i] = symmetricDistances[i, j];
symmetricWeights[i, j] = random.Next(ProblemSize * 100);
symmetricWeights[j, i] = symmetricWeights[i, j];
asymmetricDistances[i, j] = random.Next(ProblemSize * 100);
asymmetricDistances[j, i] = random.Next(ProblemSize * 100);
asymmetricWeights[i, j] = random.Next(ProblemSize * 100);
asymmetricWeights[j, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalDistances[i, j] = random.Next(ProblemSize * 100);
nonZeroDiagonalDistances[j, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[i, j] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[j, i] = random.Next(ProblemSize * 100);
}
nonZeroDiagonalDistances[i, i] = random.Next(ProblemSize * 100);
nonZeroDiagonalWeights[i, i] = random.Next(ProblemSize * 100);
}
int index = random.Next(ProblemSize);
if (nonZeroDiagonalDistances[index, index] == 0)
nonZeroDiagonalDistances[index, index] = random.Next(1, ProblemSize * 100);
index = random.Next(ProblemSize);
if (nonZeroDiagonalWeights[index, index] == 0)
nonZeroDiagonalWeights[index, index] = random.Next(1, ProblemSize * 100);
assignment = new Permutation(PermutationTypes.Absolute, ProblemSize, random);
}
示例2: Current
public void Current()
{
DoubleMatrix test = new DoubleMatrix(new double[2, 2] { { 1, 2 }, { 3, 4 } });
IEnumerator enumerator = test.GetEnumerator();
bool movenextresult;
movenextresult = enumerator.MoveNext();
Assert.IsTrue(movenextresult);
Assert.AreEqual(enumerator.Current, test[0, 0]);
movenextresult = enumerator.MoveNext();
Assert.IsTrue(movenextresult);
Assert.AreEqual(enumerator.Current, test[1, 0]);
movenextresult = enumerator.MoveNext();
Assert.IsTrue(movenextresult);
Assert.AreEqual(enumerator.Current, test[0, 1]);
movenextresult = enumerator.MoveNext();
Assert.IsTrue(movenextresult);
Assert.AreEqual(enumerator.Current, test[1, 1]);
movenextresult = enumerator.MoveNext();
Assert.IsFalse(movenextresult);
}
示例3: Apply
/// <summary>
/// Checks if all elements of the given <paramref name="vector"/> are inside the bounds and if not, elements are set to the respective values of the bounds.
/// </summary>
/// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
/// <param name="vector">The vector to check.</param>
/// <returns>The corrected real vector.</returns>
public static void Apply(RealVector vector, DoubleMatrix bounds) {
for (int i = 0; i < vector.Length; i++) {
double min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1];
if (vector[i] < min) vector[i] = min;
if (vector[i] > max) vector[i] = max;
}
}
示例4: run
internal static ArrayList run(IList para)
{
modshogun.init_shogun_with_defaults();
int degree = (int)((int?)para[0]);
string[] fm_train_dna = Load.load_dna("../data/fm_train_dna.dat");
string[] fm_test_dna = Load.load_dna("../data/fm_test_dna.dat");
StringCharFeatures feats_train = new StringCharFeatures(fm_train_dna, DNA);
StringCharFeatures feats_test = new StringCharFeatures(fm_test_dna, DNA);
WeightedDegreeStringKernel kernel = new WeightedDegreeStringKernel(feats_train, feats_train, degree);
double[] w = new double[degree];
double sum = degree * (degree + 1)/2;
for (int i = 0; i < degree; i++)
{
w[i] = (degree - i)/sum;
}
DoubleMatrix weights = new DoubleMatrix(1, degree, w);
kernel.set_wd_weights(weights);
DoubleMatrix km_train = kernel.get_kernel_matrix();
kernel.init(feats_train, feats_test);
DoubleMatrix km_test = kernel.get_kernel_matrix();
ArrayList result = new ArrayList();
result.Add(km_train);
result.Add(km_test);
result.Add(kernel);
modshogun.exit_shogun();
return result;
}
示例5: DoubleQRDecompTest
static DoubleQRDecompTest()
{
DoubleMatrix a = new DoubleMatrix(3);
a[0,0] = -1.0;
a[0,1] = 5.0;
a[0,2] = 6.0;
a[1,0] = 3.0;
a[1,1] = -6.0;
a[1,2] = 1.0;
a[2,0] = 6.0;
a[2,1] = 8.0;
a[2,2] = 9.0;
qr = new DoubleQRDecomp(a);
a = new DoubleMatrix(2,3);
a[0,0] = -1.0;
a[0,1] = 5.0;
a[0,2] = 6.0;
a[1,0] = 3.0;
a[1,1] = -6.0;
a[1,2] = 1.0;
wqr = new DoubleQRDecomp(a);
a = new DoubleMatrix(3,2);
a[0,0] = -1.0;
a[0,1] = 5.0;
a[1,0] = 3.0;
a[1,1] = -6.0;
a[2,0] = 6.0;
a[2,1] = 8.0;
lqr = new DoubleQRDecomp(a);
}
示例6: Apply
public static double Apply(Permutation assignment, TranslocationMove move, DoubleMatrix weights, DoubleMatrix distances) {
double moveQuality = 0;
int min = Math.Min(move.Index1, move.Index3);
int max = Math.Max(move.Index2, move.Index3 + (move.Index2 - move.Index1));
int iOffset, changeOffset;
if (move.Index1 < move.Index3) {
iOffset = move.Index2 - move.Index1 + 1;
changeOffset = min + max - move.Index2;
} else {
iOffset = move.Index1 - move.Index3;
changeOffset = min + move.Index2 - move.Index1 + 1;
}
for (int i = min; i <= max; i++) {
if (i == changeOffset) iOffset -= (max - min + 1);
int jOffset = ((move.Index1 < move.Index3) ? (move.Index2 - move.Index1 + 1) : (move.Index1 - move.Index3));
for (int j = 0; j < assignment.Length; j++) {
moveQuality -= weights[i, j] * distances[assignment[i], assignment[j]];
if (j < min || j > max) {
moveQuality -= weights[j, i] * distances[assignment[j], assignment[i]];
moveQuality += weights[i, j] * distances[assignment[i + iOffset], assignment[j]];
moveQuality += weights[j, i] * distances[assignment[j], assignment[i + iOffset]];
} else {
if (j == changeOffset) jOffset -= (max - min + 1);
moveQuality += weights[i, j] * distances[assignment[i + iOffset], assignment[j + jOffset]];
}
}
}
return moveQuality;
}
示例7: EvaluateByCoordinates
public static double EvaluateByCoordinates(Permutation permutation, TranslocationMove move, DoubleMatrix coordinates, TSPTranslocationMovePathEvaluator evaluator) {
if (move.Index1 == move.Index3
|| move.Index2 == permutation.Length - 1 && move.Index3 == 0
|| move.Index1 == 0 && move.Index3 == permutation.Length - 1 - move.Index2) return 0;
int edge1source = permutation.GetCircular(move.Index1 - 1);
int edge1target = permutation[move.Index1];
int edge2source = permutation[move.Index2];
int edge2target = permutation.GetCircular(move.Index2 + 1);
int edge3source, edge3target;
if (move.Index3 > move.Index1) {
edge3source = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1);
edge3target = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1 + 1);
} else {
edge3source = permutation.GetCircular(move.Index3 - 1);
edge3target = permutation[move.Index3];
}
double moveQuality = 0;
// remove three edges
moveQuality -= evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge1target, 0], coordinates[edge1target, 1]);
moveQuality -= evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
moveQuality -= evaluator.CalculateDistance(coordinates[edge3source, 0], coordinates[edge3source, 1],
coordinates[edge3target, 0], coordinates[edge3target, 1]);
// add three edges
moveQuality += evaluator.CalculateDistance(coordinates[edge3source, 0], coordinates[edge3source, 1],
coordinates[edge1target, 0], coordinates[edge1target, 1]);
moveQuality += evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
coordinates[edge3target, 0], coordinates[edge3target, 1]);
moveQuality += evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
return moveQuality;
}
示例8: Apply
/// <summary>
/// Performs a breeder genetic algorithm manipulation on the given <paramref name="vector"/>.
/// </summary>
/// <param name="random">A random number generator.</param>
/// <param name="vector">The real vector to manipulate.</param>
/// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
/// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param>
public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, DoubleValue searchIntervalFactor) {
int length = vector.Length;
double prob, value;
do {
value = Sigma(random);
} while (value == 0);
prob = 1.0 / (double)length;
bool wasMutated = false;
for (int i = 0; i < length; i++) {
if (random.NextDouble() < prob) {
double range = bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
if (random.NextDouble() < 0.5) {
vector[i] = vector[i] + value * searchIntervalFactor.Value * range;
} else {
vector[i] = vector[i] - value * searchIntervalFactor.Value * range;
}
wasMutated = true;
}
}
// make sure at least one gene was mutated
if (!wasMutated) {
int pos = random.Next(length);
double range = bounds[pos % bounds.Rows, 1] - bounds[pos % bounds.Rows, 0];
if (random.NextDouble() < 0.5) {
vector[pos] = vector[pos] + value * searchIntervalFactor.Value * range;
} else {
vector[pos] = vector[pos] - value * searchIntervalFactor.Value * range;
}
}
}
示例9: GetChannel
public static DoubleMatrix GetChannel(this MatrixBase<YCbCrColor> matrix, ChannelType channelType)
{
var ret = new DoubleMatrix(matrix.RowCount, matrix.ColumnCount);
for (int i = 0; i < matrix.RowCount; i++)
{
for (int j = 0; j < matrix.ColumnCount; j++)
{
switch (channelType)
{
case ChannelType.Y:
ret[i, j] = matrix[i, j].Y;
break;
case ChannelType.Cr:
ret[i, j] = matrix[i, j].Cr;
break;
case ChannelType.Cb:
ret[i, j] = matrix[i, j].Cb;
break;
default:
throw new ArgumentOutOfRangeException("channelType");
}
}
}
return ret;
}
示例10: Calculate
public void Calculate(DoubleMatrix i_TargetMapping)
{
if (m_SourceMapping != null)
{
m_PixelMapping = pixelMapping(m_SourceMapping, i_TargetMapping, m_MeshSize);
}
}
示例11: Point2D
/***********************/
/* PUBLIC CONSTRUCTORS */
/***********************/
/// <summary>Instantiates a new 2d point with the specified x and y
/// coordinates. Creates a new underlying matrix data source</summary>
/// <param name="x">x-coordinate of this 2d point</param>
/// <param name="y">y-coordinate of this 2d point</param>
public Point2D(Double x, Double y)
{
_matrix = new DoubleMatrix(1, 3);
_matrix[0, 0] = x;
_matrix[0, 1] = y;
_matrix[0, 2] = 1F;
}
示例12: Randomize
private DoubleArray Randomize(IRandom random, int length, DoubleMatrix bounds) {
var result = new DoubleArray(length);
for (int i = 0; i < length; i++) {
result[i] = random.NextDouble() * bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
}
return result;
}
示例13: KruskalShepard
/// <summary>
/// Performs the Kruskal-Shepard algorithm and applies a gradient descent method
/// to fit the coordinates such that the difference between the fit distances
/// and the dissimilarities is minimal.
/// </summary>
/// <remarks>
/// It will use a pre-initialized x,y-coordinates matrix as a starting point of the gradient descent.
/// </remarks>
/// <param name="dissimilarities">A symmetric NxN matrix that specifies the dissimilarities between each element i and j. Diagonal elements are ignored.</param>
/// <param name="coordinates">The Nx2 matrix of initial coordinates.</param>
/// <param name="maximumIterations">The number of iterations for which the algorithm should run.
/// In every iteration it tries to find the best location for every item.</param>
/// <returns>A Nx2 matrix where the first column represents the x- and the second column the y coordinates.</returns>
public static DoubleMatrix KruskalShepard(DoubleMatrix dissimilarities, DoubleMatrix coordinates, int maximumIterations = 10) {
int dimension = dissimilarities.Rows;
if (dimension != dissimilarities.Columns || coordinates.Rows != dimension) throw new ArgumentException("The number of coordinates and the number of rows and columns in the dissimilarities matrix do not match.");
double epsg = 1e-7;
double epsf = 0;
double epsx = 0;
int maxits = 0;
alglib.minlmstate state;
alglib.minlmreport rep;
for (int iterations = 0; iterations < maximumIterations; iterations++) {
bool changed = false;
for (int i = 0; i < dimension; i++) {
double[] c = new double[] { coordinates[i, 0], coordinates[i, 1] };
try {
alglib.minlmcreatevj(dimension - 1, c, out state);
alglib.minlmsetcond(state, epsg, epsf, epsx, maxits);
alglib.minlmoptimize(state, StressFitness, StressJacobian, null, new Info(coordinates, dissimilarities, i));
alglib.minlmresults(state, out c, out rep);
} catch (alglib.alglibexception) { }
if (!double.IsNaN(c[0]) && !double.IsNaN(c[1])) {
changed = changed || (coordinates[i, 0] != c[0]) || (coordinates[i, 1] != c[1]);
coordinates[i, 0] = c[0];
coordinates[i, 1] = c[1];
}
}
if (!changed) break;
}
return coordinates;
}
示例14: MichalewiczNonUniformAllPositionsManipulatorApplyTest
public void MichalewiczNonUniformAllPositionsManipulatorApplyTest() {
TestRandom random = new TestRandom();
RealVector parent, expected;
DoubleValue generationsDependency;
DoubleMatrix bounds;
IntValue currentGeneration, maximumGenerations;
bool exceptionFired;
// The following test is not based on published examples
random.Reset();
random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 };
parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
expected = new RealVector(new double[] { 0.45, 0.22, 0.3, 0.6, 0.14 });
bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
generationsDependency = new DoubleValue(0.1);
currentGeneration = new IntValue(1);
maximumGenerations = new IntValue(4);
MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
// The following test is not based on published examples
exceptionFired = false;
random.Reset();
random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 };
parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
generationsDependency = new DoubleValue(0.1);
currentGeneration = new IntValue(5); //current generation > max generation
maximumGenerations = new IntValue(4);
try {
MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
} catch (System.ArgumentException) {
exceptionFired = true;
}
Assert.IsTrue(exceptionFired);
}
示例15: CalculatePhenotypeDistance
public static double CalculatePhenotypeDistance(Permutation a, Permutation b, DoubleMatrix weights, DoubleMatrix distances) {
Dictionary<double, Dictionary<double, int>> alleles = new Dictionary<double, Dictionary<double, int>>();
int distance = 0, len = a.Length;
for (int x = 0; x < len; x++) {
for (int y = 0; y < len; y++) {
// there's a limited universe of double values as they're all drawn from the same matrix
double dA = distances[a[x], a[y]], dB = distances[b[x], b[y]];
if (dA == dB) continue;
Dictionary<double, int> dAlleles;
if (!alleles.ContainsKey(weights[x, y])) {
dAlleles = new Dictionary<double, int>();
alleles.Add(weights[x, y], dAlleles);
} else dAlleles = alleles[weights[x, y]];
int countA = 1, countB = -1;
if (dAlleles.ContainsKey(dA)) countA += dAlleles[dA];
if (dAlleles.ContainsKey(dB)) countB += dAlleles[dB];
if (countA <= 0) distance--; // we've found in A an allele that was present in B
else distance++; // we've found in A a new allele
dAlleles[dA] = countA;
if (countB >= 0) distance--; // we've found in B an allele that was present in A
else distance++; // we've found in B a new allele
dAlleles[dB] = countB;
}
}
return distance / (double)(2 * len * len);
}