private Layer(string id, int length = 1, bool biased = true, IActivationFunction aFunc = null, IWeightFunction wFunc = null, IInputFunction iFunc = null, IWeightInitializer wInit = null) { this.id = id; this.length = length; this.biased = biased; if (aFunc != null) { this.aFunc = aFunc; } if (wFunc != null) { this.wFunc = wFunc; } if (iFunc != null) { this.iFunc = iFunc; } if (wInit != null) { this.wInit = wInit; } if (biased) { this.biases = this.wInit != null? this.wInit.Initialize(this.length) : Utils.WeightInitializers.InitZero.Initialize(this.length); } }
private void Fix(Hole hole, IWeightFunction weightFunction) { foreach (var pix in hole.HolePixels) { FillPixelWithWeightFunction(hole, pix, weightFunction); } }
private Tuple <Type, object> EvaluateCreateLayer(ParseTreeNode node) { var layerParams = EvaluateKeyValuePair(node.ChildNodes[0]); int length = 1; bool biased = true; IActivationFunction aFunc = null; IInputFunction iFunc = null; IWeightFunction wFunc = null; IWeightInitializer wInit = null; if (!layerParams.ContainsKey("id")) { throw new Exception("ID is necessary to initialize a layer!"); } if (layerParams.ContainsKey("length")) { length = Int32.Parse(layerParams["length"]); } if (layerParams.ContainsKey("biased")) { biased = bool.Parse(layerParams["biased"]); } if (layerParams.ContainsKey("activationFunction")) { aFunc = (IActivationFunction)(typeof(ActivationFunctions) .GetField(layerParams["activationFunction"]) .GetValue(null)); } if (layerParams.ContainsKey("weightFunction")) { wFunc = (IWeightFunction)(typeof(WeightFunctions) .GetField(layerParams["weightFunction"]) .GetValue(null)); } if (layerParams.ContainsKey("inputFunction")) { iFunc = (IInputFunction)(typeof(InputFunctions) .GetField(layerParams["inputFunction"]) .GetValue(null)); } if (layerParams.ContainsKey("weightInitializer")) { wInit = (IWeightInitializer)(typeof(WeightInitializers) .GetField(layerParams["weightInitializer"]) .GetValue(null)); } var layer = Layer.Create(layerParams["id"], length: length, aFunc: aFunc, wFunc: wFunc, iFunc: iFunc, wInit: wInit, biased: biased); return(new Tuple <Type, object>(typeof(Layer), layer)); }
private void FillPixelWithWeightFunction(Hole hole, Pixel pix, IWeightFunction weightFunction) { if (pix.Value != -1) { return; } float numerator = 0; float denominator = 0; foreach (var yi in hole.Boundary) { var w = weightFunction.GetWeight(yi, pix); numerator += (w * yi.Value); denominator += w; } pix.Value = numerator / denominator; }
//rely on weight getting written later private bool WriteWeightFunction(JsonWriter writer, IWeightFunction value, JsonSerializer serializer) => value != null;
//rely on weight getting written later private bool WriteWeightFunction(JsonWriter writer, IWeightFunction value, JsonSerializer serializer) => value != null;
/// <summary> /// Fills holes using weight function /// </summary> /// <param name="weightFunction"></param> public void FillHoleWithWeightFunction(Hole hole, IWeightFunction weightFunction) { Fix(hole, weightFunction); _image.IsHoled = false; }
/// <summary> /// Fixes hole. Default implementation of interface - using supplied weight function /// </summary> /// <param name="hole"></param> public void FixHole(Hole hole, IWeightFunction weightFunction) { FillHoleWithWeightFunction(hole, weightFunction); }
public MultiRepresentationWeightFunction <TDictionary> Product(MultiRepresentationWeightFunction <TDictionary> weightFunction) { if (IsCanonicZero() || weightFunction.IsCanonicZero()) { return(Zero()); } PointMassWeightFunction pointMass = null; IWeightFunction other = null; if (this.weightFunction is PointMassWeightFunction thisPointMass) { pointMass = thisPointMass; other = weightFunction.weightFunction; } else if (weightFunction.weightFunction is PointMassWeightFunction otherPointMass) { pointMass = otherPointMass; other = this.weightFunction; } if (pointMass != null && !other.UsesGroups) { var logValue = other.GetLogValue(pointMass.Point); if (double.IsNegativeInfinity(logValue)) { return(Zero()); } else if (logValue == 0.0) { return(FromPointMass(pointMass)); } else { return(FromDictionary( DictionaryWeightFunction <TDictionary> .FromDistinctWeights( new[] { new KeyValuePair <TSequence, Weight>(pointMass.Point, Weight.FromLogValue(logValue)) }))); } } TDictionary dictionary = null; if (this.weightFunction is TDictionary thisDictionary) { if (weightFunction.weightFunction is TDictionary secondDictionary) { return(FromDictionary(thisDictionary.Product(secondDictionary))); } dictionary = thisDictionary; other = weightFunction.weightFunction; } else if (weightFunction.weightFunction is TDictionary otherDictionary) { dictionary = otherDictionary; other = this.weightFunction; } if (dictionary != null && !other.UsesGroups) { var resultList = new List <KeyValuePair <TSequence, Weight> >(dictionary.Dictionary.Count); foreach (var kvp in dictionary.Dictionary) { if (!kvp.Value.IsZero) { var otherLogValue = other.GetLogValue(kvp.Key); if (!double.IsNegativeInfinity(otherLogValue)) { resultList.Add(new KeyValuePair <TSequence, Weight>(kvp.Key, kvp.Value * Weight.FromLogValue(otherLogValue))); } } } if (resultList.Count == 0) { return(Zero()); } else if (resultList.Count == 1 && resultList[0].Value.LogValue == 0.0) { return(FromPoint(resultList[0].Key)); } else { return(FromDictionary( DictionaryWeightFunction <TDictionary> .FromDistinctWeights(resultList))); } } return(FromAutomaton(AsAutomaton().Product(weightFunction.AsAutomaton()))); }
/// <summary> /// Internal Default Constuctor. /// </summary> internal RankingOptions() { this.CacheDuration = TimeSpan.Zero; this.TopN = 25; this.weightFunc = WeightFunction.Empty; }
public RankingOptions(TimeSpan?cacheDuration = null, long topN = -1, IWeightFunction weightFunc = null) { this.CacheDuration = cacheDuration; this.TopN = topN; this.weightFunc = weightFunc != null ? weightFunc : WeightFunction.Empty; }
public static Layer Create(string id, int length = 1, bool biased = false, IActivationFunction aFunc = null, IWeightFunction wFunc = null, IInputFunction iFunc = null, IWeightInitializer wInit = null) { return(new Layer(id, length, biased, aFunc, wFunc, iFunc, wInit)); }
private MultiRepresentationWeightFunction(IWeightFunction weightFunction) { this.weightFunction = weightFunction; }