protected override void ProcessRecord() { IList <Value> results; if (ParameterSetName == "Hashtable") { results = FunctionInvoke.Invoke(Function, Arguments, Device, false); } else if (ParameterSetName == "DataSourceSet") { results = FunctionInvoke.Invoke(Function, DataSourceSet, Device, false); } else { DataNameToInputMap map = new DataNameToInputMap(new Function[] { Function }, DataNameToInputMap); Minibatch batch = null; var values = new List <Value>(); do { batch = Sampler.GetNextMinibatch(Device); map.InitializeByMinibatch(batch); values.AddRange(FunctionInvoke.Invoke(Function, batch, map, Device)); }while (!batch.SweepEnd); results = values; } foreach (var r in results) { WriteObject(r); } }
public static Value[] Invoke(PSObject func, object arguments = null, DataNameToInputMap map = null) { Function f = ToFunction(func); if (arguments == null) return FunctionInvoke.Invoke(f, new Dictionary<Variable, Value>(), null, false); if (arguments is Dictionary<Variable, Value> vvdic) return FunctionInvoke.Invoke(f, vvdic, null, false); if (arguments is Dictionary<string, Value> svdic) return FunctionInvoke.Invoke(f, svdic, null, false); if (arguments is Hashtable ht) return FunctionInvoke.Invoke(f, ht, null, false); if (arguments is Minibatch mb) return FunctionInvoke.Invoke(f, mb, map, null, false); if (arguments is IDictionary<string, IDataSource<float>> sddic) return FunctionInvoke.Invoke(f, sddic, null, false); if (arguments is DataSourceSet dss) return FunctionInvoke.Invoke(f, dss, null, false); throw new ArgumentException("Invalid type: arguments"); }
private IDataSource <float>[] GetValues(Function func) { if (!_showValues) { return(null); } Value[] values = null; try { if (_minibatch == null) { values = FunctionInvoke.Invoke(func, _arguments, null, false); } else { values = FunctionInvoke.Invoke(func, _minibatch, _map, null, false); } } catch (Exception) { // Pass } return(values.Select(x => DataSourceFactory.FromValue(x)).ToArray()); }
public override Minibatch GetNextMinibatch(DeviceDescriptor device = null) { if (device == null) { device = DeviceDescriptor.UseDefaultDevice(); } Value value; if (InputVariable == null) { value = FunctionInvoke.Invoke(Expression, new Dictionary <Variable, Value>(), device, false)[0]; } else { value = FunctionInvoke.Invoke(Expression, new Dictionary <Variable, Value>() { { InputVariable, PrevValue } }, device, false)[0]; } int sampleCount = 0; int rank = value.Shape.Rank; if (rank == 0) { sampleCount = 1; } else { sampleCount = value.Shape[rank - 1]; } ++Iterations; var sweepEnd = (Iterations + 1) % IterationsPerEpoch == 0; var data = new MinibatchData(value, (uint)sampleCount, sweepEnd); var minibatch = new Minibatch(); minibatch.Add(Name, data); PrevValue = value; return(minibatch); }