public void CopyTo(RNdMatrix dist) { if (IsSimilarity(this, dist)) { Array.Copy(Data, 0, dist.Data, 0, Data.Length); } }
protected override void ConfirmField(object shared) { double sd = Math.Sqrt(1.0 / (InArea)); if (shared != null) { var obj = shared as Utility.Shared.ModelParameter; var w = new Utility.Shared.ModelParameter.WeightData(1); w.Data[0] = new Components.RNdMatrix(InArea + 1, OutArea, 1, 1); Utility.Randomizer.Noize(ref w.Data[0].Data, Utility.Randomizer.Sign.Both, 0, sd); obj.Weignt.Add(w); Weight = new Components.RNdMatrix(w.Data[0].Shape); Weight.Data = (w.Data[0].Data.Clone()) as Components.Real[]; WeightDifference = w.Difference.Clone() as Components.Real[]; } else { if (!ObjectDecoded) { Weight = (new Components.RNdMatrix(InArea + 1, OutArea, 1, 1)) as Components.RNdMatrix; Utility.Randomizer.Noize(ref Weight.Data, Utility.Randomizer.Sign.Both, 0, sd); } WeightDifference = new Components.Real[1]; } }
public override RNdObject Clone() { var matrix = new RNdMatrix() { Data = (Real[])Data.Clone(), Shape = (int[])Shape.Clone() }; return(matrix); }
public override RNdObject Abs() { var matrix = new RNdMatrix() { Data = ((Real[])Data.Clone()).Select(x => (Real)Math.Abs(x)).ToArray(), Shape = (int[])Shape.Clone() }; return(matrix); }
public override RNdObject Clone() { var cl = new Real[Data.Length]; Array.Copy(Data, 0, cl, 0, Data.Length); var matrix = new RNdMatrix() { Hash = this.Hash, Data = cl, Shape = (int[])Shape.Clone() }; return(matrix); }
protected override void ConfirmField(object shared) { CompressSize = CompressSize <= 0 ? 1 : CompressSize; ExpandSize = ExpandSize <= 0 ? 1 : ExpandSize; OutputChannels = InputChannels; OutWidth = (int)(((double)ExpandSize / (double)CompressSize) * InWidth); OutHeight = (int)(((double)ExpandSize / (double)CompressSize) * InHeight); Map = new Components.RNdMatrix(BatchCount, OutputChannels, InWidth, InHeight); if (shared != null) { var obj = shared as Utility.Shared.ModelParameter; var w = new Utility.Shared.ModelParameter.WeightData(0); obj.Weignt.Add(w); } }
public static void TestStart_ImageConvolusion() { Components.Imaging.Core.Instance.Initialize(State.CaptureMode.Device_Camera); (new System.Threading.Tasks.Task(() => { Random rand = new Random(); RNdMatrix inmat = new RNdMatrix(1, 3, 340, 240); RNdMatrix outmat = new RNdMatrix(1, 3, 340, 240); var unit = new GPGPU.Layer.Unit.Convolution.Convolution() { Activation = true, KernelSize = 5, OutputChannels = 3, Rho = 0.001, }; unit.Initialize(inmat.Clone()); unit.Confirm(); int counter = 0; double time = 0; while (true) { time = 0; var input = Imaging.Core.Instance.GetFrame(inmat.Shape); unit.Input = input.Clone(); time += unit.Action(State.ActionMode.Forward); var sigma = unit.Output - input; unit.Sigma = sigma; //time += unit.Action(ActionMode.Back); unit.Output.Show("output", 0); sigma.Show("sigma", 0); Terminal.WriteLine(State.EventState.State, "Step:{0}, TimeSpan[ms]:{1}, FPS:{2}", counter++, (int)time, (int)(1000.0 / time)); } })).Start(); }
protected override void ConfirmField(object shared) { OutWidth = (int)(OutScale * InWidth); OutHeight = (int)(OutScale * InHeight); double sd_b = Math.Sqrt(1.0 / (InputChannels * KernelLength)); double sd_k = Math.Sqrt(1.0 / (InputChannels * KernelLength)); if (shared != null) { var obj = shared as Utility.Shared.ModelParameter; var w = new Utility.Shared.ModelParameter.WeightData(2); w.Data[0] = new Components.RNdMatrix(OutputChannels, 1, 1, 1); w.Data[1] = new Components.RNdMatrix(InputChannels, OutputChannels, 2 * KernelSize + 1, 2 * KernelSize + 1); Utility.Randomizer.Noize(ref w.Data[0].Data, Utility.Randomizer.Sign.Both, 0, sd_b); Utility.Randomizer.Noize(ref w.Data[1].Data, Utility.Randomizer.Sign.Both, 0, sd_k); obj.Weignt.Add(w); WeightBias = new Components.RNdMatrix(w.Data[0].Shape); WeightBias.Data = (w.Data[0].Data.Clone()) as Components.Real[]; WeightKernel = new Components.RNdMatrix(w.Data[1].Shape); WeightKernel.Data = (w.Data[1].Data.Clone()) as Components.Real[]; WeightDifference = w.Difference.Clone() as Components.Real[]; } else { if (!ObjectDecoded) { WeightBias = (new Components.RNdMatrix(OutputChannels, 1, 1, 1)) as Components.RNdMatrix; WeightKernel = (new Components.RNdMatrix(InputChannels, OutputChannels, 2 * KernelSize + 1, 2 * KernelSize + 1)) as Components.RNdMatrix; Utility.Randomizer.Noize(ref WeightBias.Data, Utility.Randomizer.Sign.Both, 0, sd_b); Utility.Randomizer.Noize(ref WeightKernel.Data, Utility.Randomizer.Sign.Both, 0, sd_k); } WeightDifference = new Components.Real[2]; } }
protected override void DecodeOption(List <object> values) { Weight = values[0] as RNdMatrix; }
protected override void DecodeOption(List <object> values) { WeightBias = values[0] as RNdMatrix; WeightKernel = values[1] as RNdMatrix; }