public static HeterogenousNGrams <T> BuildNGrams(int p1, int p2, List <T> corp) { corp.NullCheck(); (p1 > 0).AssertTrue(); (p2 > p1).AssertTrue(); return(new HeterogenousNGrams <T>(Enumerable.Range(p1, p2 - p1).Select(x => HomogenousNGrams <T> .BuildNGrams(x, corp)).ToList(), p1, p2)); }
public DiscreteDataRetriever(List <Chord> chordsInOrder, int clusterSize = 2, int windowSize = 20) { chordsInOrder.NullCheck(); chordsInOrder.Any().AssertTrue(); this.Chords = chordsInOrder.AsReadOnly(); this.WindowSize = windowSize; this.NGramSize = clusterSize; this.HomogenousWindowingData = HomogenousNGrams <Chord> .BuildNGrams(this.NGramSize, this.Chords.ToList()); this.badOkayGoodChords = Tuple.Create <List <NGram <Chord>[]>, List <NGram <Chord>[]>, List <NGram <Chord>[]> >(this.RetrieveBad(), this.RetrieveOkay(), this.RetrieveGood()); }
public DiscreteDataRetriever(List<Chord> chordsInOrder, int clusterSize = 2, int windowSize = 20) { chordsInOrder.NullCheck(); chordsInOrder.Any().AssertTrue(); this.Chords = chordsInOrder.AsReadOnly(); this.WindowSize = windowSize; this.NGramSize = clusterSize; this.HomogenousWindowingData = HomogenousNGrams<Chord>.BuildNGrams(this.NGramSize, this.Chords.ToList()); this.badOkayGoodChords = Tuple.Create<List<NGram<Chord>[]>, List<NGram<Chord>[]>, List<NGram<Chord>[]>>(this.RetrieveBad(), this.RetrieveOkay(), this.RetrieveGood()); }
public static Dictionary <NGram <T>, HashSet <NGram <T> > > BuildBlockedNGrams(List <NGram <T>[]> grams, int min, int max) { grams.NullCheck(); var blockedNGrams = new Dictionary <NGram <T>, HashSet <NGram <T> > >(); foreach (var item in grams) { foreach (var gram in item) { if (!blockedNGrams.ContainsKey(gram)) { blockedNGrams.Add(gram, BuildSingleBlock(grams, gram, min, max)); } } } return(blockedNGrams); }
private Chord(List <MidiEvent> messages, List <FullNote> notes) { messages.NullCheck(); notes.NullCheck(); messages.Any().AssertTrue(); notes.Any().AssertTrue(); this.AbsoluteTick = messages.Last().AbsoluteTicks; this.DeltaTick = messages.Sum(x => x.DeltaTicks); this.MidiChunk = messages.AsReadOnly(); this.Notes = new HashSet <FullNote>(notes) .ToList() .AsReadOnly(); this.hash = HashHelper.FNVHashCode(this.Notes.ToArray()); }
public static HomogenousNGrams <T> BuildNGrams(int n, List <T> entities) { (n > 0).AssertTrue(); (entities.Count >= n).AssertTrue(); entities.NullCheck(); List <NGram <T> > list = new List <NGram <T> >(); int count = entities.Count - n; for (int i = 0; i < count; i++) { T[] ngram = new T[n]; entities.CopyTo(i, ngram, 0, n); list.Add(new NGram <T>(ngram)); } list.Add(new NGram <T>(entities.Skip(count).ToArray())); return(new HomogenousNGrams <T>(list, n)); }
public static HashSet <CycleData <T> > BruteForceAlgorithm <T>(List <T> list) where T : IEquatable <T> { list.NullCheck(); HashSet <CycleData <T> > data = new HashSet <CycleData <T> >(); int count = list.Count / 2; for (int startIndex = 0; startIndex < count; startIndex++) { int maxCount = (list.Count - startIndex) / 2; for (int i = 2; i < maxCount; i++) { data.Add(CycleFinder.BruteForceSingle <T>(list, startIndex, i)); } } return(data); }
public DiscreteNeuralNetworkByChord(List<NGram<Chord>[]> bad, List<NGram<Chord>[]> okay, List<NGram<Chord>[]> good, IActivationFunction function) { bad.NullCheck(); okay.NullCheck(); good.NullCheck(); bad.Any().AssertTrue(); okay.Any().AssertTrue(); good.Any().AssertTrue(); List<Tuple<double[], double[]>> input = new List<Tuple<double[], double[]>>(bad.Count + okay.Count + good.Count); input.AddRange( bad.Select(x => new Tuple<double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat<double>(DiscreteNeuralNetworkByChord.BADWEIGHT, bad.Count).ToArray()))); input.AddRange( okay.Select(x => new Tuple<double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat<double>(OkayWeight, okay.Count).ToArray()))); input.AddRange( good.Select(x => new Tuple<double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat<double>(DiscreteNeuralNetworkByChord.GOODWEIGHT, good.Count).ToArray()))); this.Max = input.Max(x => x.Item1.Max()); int minIndex = input.Min(x => x.Item1.Length); var normalized = input.Select(item => Tuple.Create(item.Item1.Take(minIndex).Select(x => x / this.Max).ToArray(), item.Item2.Take(minIndex).ToArray())).ToArray(); this.trainingData = normalized.ToArray(); this.ActivationNetwork = new ActivationNetwork(function, this.trainingData.Max(y => y.Item1.Length), (HiddenLayerSize == 0) ? 23 : HiddenLayerSize, 1); this.LearningMethod = new ResilientBackpropagationLearning(this.ActivationNetwork); this.ActivationNetwork.Randomize(); }
public DiscreteNeuralNetworkByChord(List <NGram <Chord>[]> bad, List <NGram <Chord>[]> okay, List <NGram <Chord>[]> good, IActivationFunction function) { bad.NullCheck(); okay.NullCheck(); good.NullCheck(); bad.Any().AssertTrue(); okay.Any().AssertTrue(); good.Any().AssertTrue(); List <Tuple <double[], double[]> > input = new List <Tuple <double[], double[]> >(bad.Count + okay.Count + good.Count); input.AddRange( bad.Select(x => new Tuple <double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat <double>(DiscreteNeuralNetworkByChord.BADWEIGHT, bad.Count).ToArray()))); input.AddRange( okay.Select(x => new Tuple <double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat <double>(OkayWeight, okay.Count).ToArray()))); input.AddRange( good.Select(x => new Tuple <double[], double[]>( x.SelectMany(y => y.SelectMany(p => ConvertChordIntoTrainingInput(p))).ToArray(), Enumerable.Repeat <double>(DiscreteNeuralNetworkByChord.GOODWEIGHT, good.Count).ToArray()))); this.Max = input.Max(x => x.Item1.Max()); int minIndex = input.Min(x => x.Item1.Length); var normalized = input.Select(item => Tuple.Create(item.Item1.Take(minIndex).Select(x => x / this.Max).ToArray(), item.Item2.Take(minIndex).ToArray())).ToArray(); this.trainingData = normalized.ToArray(); this.ActivationNetwork = new ActivationNetwork(function, this.trainingData.Max(y => y.Item1.Length), (HiddenLayerSize == 0) ? 23 : HiddenLayerSize, 1); this.LearningMethod = new ResilientBackpropagationLearning(this.ActivationNetwork); this.ActivationNetwork.Randomize(); }
public Melody(List <Chord> chords) { chords.NullCheck(); this.innerChords = chords; }
public LilyPondBuilder(List<Chord> a) { a.NullCheck(); this.innerChords = a; }
public static HashSet <IntRange> Cycles <T>(List <T> list) where T : IEquatable <T> { list.NullCheck(); }
public LilyPondBuilder(List <Chord> a) { a.NullCheck(); this.innerChords = a; }