本文整理汇总了C#中Vector.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Clone方法的具体用法?C# Vector.Clone怎么用?C# Vector.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecognizeAsynchronously
public static Matrix RecognizeAsynchronously(Matrix weights, Vector input)
{
Random rand = new Random(DateTime.Now.Millisecond);
Vector oldOutput = input.Clone();
Vector newOutput = input.Clone();
int iterations = 0;
int equalTimes = 0;
while (true)
{
Console.WriteLine("iteration: {0}", iterations++);
Console.WriteLine(oldOutput);
for (int i = 0; i < input.Length; ++i)
{
newOutput[i] = weights.GetRowVector(i).ArrayMultiply(newOutput).Sum() >= 0 ? +1 : -1;
}
Console.WriteLine(newOutput);
if (newOutput.SequenceEqual(oldOutput)) //equalTimes += 1;
//else equalTimes -= 1;
//if (equalTimes >= 5)
{
Console.WriteLine("Old and new are equal");
Matrix recognized = newOutput.ToMatrixByColumns(columnSize: (int)Math.Sqrt(input.Length));
return recognized;
}
oldOutput = newOutput.Clone();
}
}
示例2: TransformedGrid
public TransformedGrid (Vector grid) {
grid_ = (Vector)grid.Clone();
transformedGrid_ = (Vector)grid.Clone();
dxm_= new Vector(grid.size());
dxp_ = new Vector(grid.size());
dx_ = new Vector(grid.size());
for (int i=1; i < transformedGrid_.size() -1 ; i++) {
dxm_[i] = transformedGrid_[i] - transformedGrid_[i-1];
dxp_[i] = transformedGrid_[i+1] - transformedGrid_[i];
dx_[i] = dxm_[i] + dxp_[i];
}
}
示例3: JakobiMatrix
public static Matrix JakobiMatrix(Vector x, Function[] f, double precision)
{
if ((f.Length > 0) && (x.Length > 0) && (precision > 0))
{
Matrix J = new Matrix(f.Length, x.Length);
Vector temp = x.Clone() as Vector;
for (int counter1 = 0; counter1 < J.Height; counter1++)
{
for (int counter2 = 0; counter2 < J.Width; counter2++)
{
temp[counter2] += precision;
J[counter1][counter2] = (f[counter1](temp) - f[counter1](x)) / precision;
temp[counter2] -= precision;
}
}
return J;
}
else
{
throw new IncorrectIncomingDataException("Dimensions of delegates or vectors or precision are incorrect.");
}
}
示例4: QpProblem
public QpProblem(Matrix<double> Q, Vector<double> g, Matrix<double> A, Vector<double> b)
{
this._Q = Q.Clone();
this._c = g.Clone();
this._A = A.Clone();
this._b = b.Clone();
}
示例5: Light
public Light(Vector direction, uint diffuse, uint specular, int highlightSheen, int highlightSpread)
{
v=direction.Clone();
v.Normalize();
this.diffuse=diffuse;
this.specular=specular;
this.highlightSheen=highlightSheen;
this.highlightSpread=highlightSpread;
}
示例6: Path
public Path(TimeGrid timeGrid, Vector values) {
timeGrid_ = timeGrid;
values_ = (Vector)values.Clone();
if (values_.empty())
values_ = new Vector(timeGrid_.size());
if (values_.size() != timeGrid_.size())
throw new ApplicationException("different number of times and asset values");
}
示例7: TridiagonalOperator
public TridiagonalOperator(Vector low, Vector mid, Vector high) {
diagonal_ = (Vector)mid.Clone();
lowerDiagonal_ = (Vector)low.Clone();
upperDiagonal_ = (Vector)high.Clone();
if (!(low.Count == mid.Count - 1))
throw new ApplicationException("wrong size for lower diagonal vector");
if (!(high.Count == mid.Count - 1))
throw new ApplicationException("wrong size for upper diagonal vector");
}
示例8: GaussianMeasurement
// Constructor
public GaussianMeasurement(uint platformID, uint sensorID,
Vector creatorUnityReference, GaussianVector gaussianVector,
Coordinate.Type coordinateType, DateTime dateTime)
{
this.platformID = platformID;
this.sensorID = sensorID;
this.creatorUnityReference = creatorUnityReference.Clone();
this.gaussianVector = gaussianVector.Clone();
this.coordinateType = coordinateType;
this.dateTime = dateTime;
}
示例9: Reflection
/// <summary>
/// Householder Reflection: Evaluate symmetric orthogonal Q such that Q*v = -sigma*||v||*e1
/// </summary>
public static Matrix Reflection(Vector v)
{
double sigma = v[0] >= 0 ? 1 : -1;
Vector u = v.Clone();
u[0] += sigma * v.Norm();
Matrix m = Matrix.Identity(v.Length, v.Length);
m.MultiplyAccumulateInplace(u.TensorMultiply(u), -2d / u.ScalarMultiply(u));
return m;
}
示例10: Evaluate
public override Vector Evaluate(Vector state, DateTime stateTime, DateTime targetTime)
{
// Compute dt
TimeSpan ts = targetTime.Subtract(stateTime);
double dt = ts.TotalSeconds;
// Create coasted vector
Vector coasted = state.Clone();
coasted[0] = state[0] + state[3] * dt;
coasted[1] = state[1] + state[4] * dt;
coasted[2] = state[2] + state[5] * dt;
// Return
return coasted;
}
示例11: Solve
public Vector Solve(Vector initialVector, double precision)
{
Vector x;
if (initialVector.Length == this.f.Length)
{
bool key = true;
Vector candidate = new Vector(this.f.Length);
x = initialVector.Clone() as Vector;
Vector f = new Vector(this.f.Length);
while (((candidate - x).Norm() > precision) || (key))
{
if (((candidate - x).Norm() > precision) && (!key))
{
x = candidate;
}
key = false;
for (int counter = 0; counter < this.f.Length; counter++)
{
f[counter] = -this.f[counter](x);
}
try
{
candidate = x + DirectMethods.GaussMethod(new SquareMatrix(DiffrerntialOperators.JakobiMatrix(x, this.f, precision)), f);
}
catch (NoSolutionException error)
{
throw new NoSolutionException("To many solutions or solution does not exists.", error);
}
}
}
else
{
throw new IncorrectIncomingDataException("Incorrect length of incming vector is set.");
}
return x;
}
示例12: HesseMatrix
public static SquareMatrix HesseMatrix(Vector x, Function f, double precision)
{
if ((x.Length > 0) && (precision > 0))
{
SquareMatrix H = new SquareMatrix(x.Length);
Vector temp = x.Clone() as Vector;
for (int counter1 = 0; counter1 < H.Height; counter1++)
{
for (int counter2 = 0; counter2 < H.Width; counter2++)
{
double sum = f(x);
temp[counter2] += precision;
temp[counter1] += precision;
sum += f(temp);
temp[counter2] -= precision;
sum -= f(temp);
temp[counter2] += precision;
temp[counter1] -= precision;
sum -= f(temp);
H[counter1][counter2] = sum / Math.Pow(precision, 2);
temp[counter2] -= precision;
}
}
return H;
}
else
{
throw new IncorrectIncomingDataException("Dimensions of delegates or vectors or precision are incorrect.");
}
}
示例13: RecognizeSynchronously
public static int RecognizeSynchronously(Matrix weights, Vector input, Vector[] samples)
{
Console.WriteLine("Recognize()");
Console.WriteLine("input:");
Vector oldOutput = input.Clone();
int recognizedSampleIndex;
int iterations = 0;
while (true)
{
iterations += 1;
Console.WriteLine("iteration: {0}", iterations);
Vector newOutput = oldOutput.Clone();
for (int r = 0; r < weights.RowCount; ++r)
{
Vector weightsRow = weights.GetRowVector(r);
newOutput[r] = weightsRow.ArrayMultiply(oldOutput).Sum() >= 0 ? +1 : -1;
}
if (newOutput.SequenceEqual(oldOutput))
{
for (int j = 0; j < samples.Length; ++j)
{
if (samples[j].SequenceEqual(newOutput))
{
recognizedSampleIndex = j;
Console.WriteLine("Recognized to be {0}", j);
return recognizedSampleIndex;
}
}
}
//Console.WriteLine("output:");
//Console.WriteLine(newOutput.ToPrettyString());
oldOutput = newOutput.Clone();
if (iterations > 100)
{
Console.WriteLine("Coulnd't recognize");
return -1;
}
}
}
示例14: PutAllPaths
public static void PutAllPaths(this List<LinkedList<Vector>> allPaths, Vector toPont, Vector position, LinkedList<Vector> path, int[,] maze)
{
if (maze[position.Y, position.X] != EmptyCell)
{
return;
}
maze[position.Y, position.X] = VisitedCell;
path.AddLast((Vector)position.Clone());
if (position.CompareTo(toPont) == 0)
{
allPaths.Add(new LinkedList<Vector>(path));
}
else
{
foreach (var direction in Directions)
{
if (IsInRange(
position.Y + direction.Y,
position.X + direction.X,
maze.GetLength(0),
maze.GetLength(1)))
{
allPaths.PutAllPaths(
toPont,
new Vector(y: position.Y + direction.Y, x: position.X + direction.X),
path,
maze);
}
}
}
path.RemoveLast();
maze[position.Y, position.X] = EmptyCell;
}
示例15: Solve
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A QR factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <param name="result">The left hand side <see cref="Matrix{T}"/>, <b>x</b>.</param>
public override void Solve(Vector<float> input, Vector<float> result)
{
// Ax=b where A is an m x n matrix
// Check that b is a column vector with m entries
if (Q.RowCount != input.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
// Check that x is a column vector with n entries
if (Q.ColumnCount != result.Count)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(Q, result);
}
var inputCopy = input.Clone();
// Compute Y = transpose(Q)*B
var column = new float[Q.RowCount];
for (var k = 0; k < Q.RowCount; k++)
{
column[k] = inputCopy[k];
}
for (var i = 0; i < Q.ColumnCount; i++)
{
float s = 0;
for (var k = 0; k < Q.RowCount; k++)
{
s += Q.At(k, i) * column[k];
}
inputCopy[i] = s;
}
// Solve R*X = Y;
for (var k = Q.ColumnCount - 1; k >= 0; k--)
{
inputCopy[k] /= FullR.At(k, k);
for (var i = 0; i < k; i++)
{
inputCopy[i] -= inputCopy[k] * FullR.At(i, k);
}
}
for (var i = 0; i < FullR.ColumnCount; i++)
{
result[i] = inputCopy[i];
}
}