private NeuroWeight(NeuroWeight <T> other) { Weight = other.Weight.CloneMatrix(); Gradient = other.Gradient.CloneMatrix(); Cache1 = other.Cache1.CloneMatrix(); Cache2 = other.Cache2.CloneMatrix(); CacheM = other.CacheM.CloneMatrix(); Timestep = other.Timestep; }
public static NeuroWeight <T> Load(Stream stream) { var result = new NeuroWeight <T>(); using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { result.Weight = MatrixFactory.Load <T>(stream); bool saveCache = reader.ReadBoolean(); bool saveGrad = reader.ReadBoolean(); if (saveCache) { result.Cache1 = MatrixFactory.Load <T>(stream); result.Cache2 = MatrixFactory.Load <T>(stream); result.CacheM = MatrixFactory.Load <T>(stream); result.Timestep = reader.ReadInt32(); } else { result.Cache1 = Matrix <T> .Build.Dense(result.Weight.RowCount, result.Weight.ColumnCount); result.Cache2 = Matrix <T> .Build.Dense(result.Weight.RowCount, result.Weight.ColumnCount); result.CacheM = Matrix <T> .Build.Dense(result.Weight.RowCount, result.Weight.ColumnCount); } if (saveGrad) { result.Gradient = MatrixFactory.Load <T>(stream); } else { result.Gradient = Matrix <T> .Build.Dense(result.Weight.RowCount, result.Weight.ColumnCount); } } return(result); }