/// <summary> /// Trains a classifier for each channel so long as (int)minSpikes worth of spikes have been collected /// for that channel in the training buffer /// </summary> private void Train() { // Clear old channel models channelsToSort = new List <int>(); channelModels.Clear(); trained = false; totalNumberOfUnits = 0; // Clear old unit dictionary unitDictionary = new Hashtable(); // Add the zero unit to the dictionary unitDictionary.Add(0, 0); // Clear the old unit2channel map unit2Channel = new Dictionary <int, int>(); // Make sure we have something in the training matrix if (trainingSpikes.Buffer.Count == 0) { throw new InvalidOperationException("The training data set was empty"); } for (int i = 0; i < numberChannels; ++i) { // Current channel int currentChannel = i; // Get the spikes that belong to this channel List <SpikeEvent> spikesOnChan = trainingSpikes.Buffer.Where(x => x.Channel == currentChannel).ToList(); // Project channel data if (spikesOnChan.Count >= minSpikes) { // Train a channel model for this channel ChannelModel thisChannelModel = new ChannelModel(currentChannel, maxK, totalNumberOfUnits, pValue, projectionDimension); // Project Data if (projectionType == "PCA") { thisChannelModel.PCCompute(spikesOnChan.ToList()); } else { thisChannelModel.HaarCompute(spikesOnChan.ToList()); } // Train Classifier thisChannelModel.Train(); // If there was a training failure (e.g. convergence) if (!thisChannelModel.trained) { continue; } // Note that we have to sort spikes on this channel channelsToSort.Add(currentChannel); // Update the unit dicationary and increment the total number of units for (int k = 1; k <= thisChannelModel.K; ++k) { unitDictionary.Add(totalNumberOfUnits + k, k); unit2Channel.Add(totalNumberOfUnits + k, i); } totalNumberOfUnits += thisChannelModel.K; // Add the channel model to the list channelModels.Add(thisChannelModel); } } }
/// <summary> /// Trains a classifier for each channel so long as (int)minSpikes worth of spikes have been collected /// for that channel in the training buffer /// </summary> private void Train() { // Clear old channel models channelsToSort = new List<int>(); channelModels.Clear(); trained = false; totalNumberOfUnits = 0; // Clear old unit dictionary unitDictionary = new Hashtable(); // Add the zero unit to the dictionary unitDictionary.Add(0, 0); // Clear the old unit2channel map unit2Channel = new Dictionary<int, int>(); // Make sure we have something in the training matrix if (trainingSpikes.Buffer.Count == 0) { throw new InvalidOperationException("The training data set was empty"); } for (int i = 0; i < numberChannels; ++i) { // Current channel int currentChannel = i; // Get the spikes that belong to this channel List<SpikeEvent> spikesOnChan = trainingSpikes.Buffer.Where(x => x.Channel == currentChannel).ToList(); // Project channel data if (spikesOnChan.Count >= minSpikes) { // Train a channel model for this channel ChannelModel thisChannelModel = new ChannelModel(currentChannel, maxK, totalNumberOfUnits, pValue, projectionDimension); // Project Data if (projectionType == "PCA") thisChannelModel.PCCompute(spikesOnChan.ToList()); else thisChannelModel.HaarCompute(spikesOnChan.ToList()); // Train Classifier thisChannelModel.Train(); // If there was a training failure (e.g. convergence) if (!thisChannelModel.trained) continue; // Note that we have to sort spikes on this channel channelsToSort.Add(currentChannel); // Update the unit dicationary and increment the total number of units for (int k = 1; k <= thisChannelModel.K; ++k) { unitDictionary.Add(totalNumberOfUnits + k, k); unit2Channel.Add(totalNumberOfUnits + k, i); } totalNumberOfUnits += thisChannelModel.K; // Add the channel model to the list channelModels.Add(thisChannelModel); } } }
/// <summary> /// Trains a classifier for each channel so long as (int)minSpikes worth of spikes have been collected /// for that channel in the training buffer. This uses to time points as the projection: The peak sample /// of the waveform and sample at some fixed (mSecToSecondSample) delay from the peak sample. Preferably, /// this should be in the middle of the AHP. /// </summary> /// <param name="peakSample"> Sample that the peak of the waveform occured at </param> /// <param name="mSecToSecondSample">Delay, in msec, to get the second data point</param> private void Train(int peakSample, double mSecToSecondSample, int sampleFreqHz) { // Clear old channel models channelsToSort = new List <int>(); channelModels.Clear(); trained = false; totalNumberOfUnits = 0; // Clear old unit dictionary unitDictionary = new Hashtable(); // Add the zero unit to the dictionary unitDictionary.Add(0, 0); // Clear the old unit2channel map unit2Channel = new Dictionary <int, int>(); // Set the inflection sample inflectionSample = peakSample; secondInflectionIndex = peakSample + (int)(sampleFreqHz * (mSecToSecondSample / 1000)); // Make sure we have something in the training matrix if (trainingSpikes.Buffer.Count == 0) { throw new InvalidOperationException("The training data set was empty"); } for (int i = 0; i < numberChannels; ++i) { // Current channel int currentChannel = i; // Get the spikes that belong to this channel List <SpikeEvent> spikesOnChan = trainingSpikes.Buffer.Where(x => x.Channel == currentChannel).ToList(); // Project channel data if (spikesOnChan.Count >= minSpikes) { // Train a channel model for this channel ChannelModel thisChannelModel = new ChannelModel(currentChannel, maxK, totalNumberOfUnits, pValue); // Project Data thisChannelModel.DoubleInflectProject(spikesOnChan.ToList(), inflectionSample, secondInflectionIndex); // Train Classifier thisChannelModel.Train(); // If there was a training failure (e.g. convergence) if (!thisChannelModel.trained) { continue; } // Note that we have to sort spikes on this channel channelsToSort.Add(currentChannel); // Update the unit dicationary and increment the total number of units for (int k = 1; k <= thisChannelModel.K; ++k) { unitDictionary.Add(totalNumberOfUnits + k, k); unit2Channel.Add(totalNumberOfUnits + k, i); } totalNumberOfUnits += thisChannelModel.K; // Add the channel model to the list channelModels.Add(thisChannelModel); } } // All finished trained = true; }
/// <summary> /// Trains a classifier for each channel so long as (int)minSpikes worth of spikes have been collected /// for that channel in the training buffer. This uses to time points as the projection: The peak sample /// of the waveform and sample at some fixed (mSecToSecondSample) delay from the peak sample. Preferably, /// this should be in the middle of the AHP. /// </summary> /// <param name="peakSample"> Sample that the peak of the waveform occured at </param> /// <param name="mSecToSecondSample">Delay, in msec, to get the second data point</param> private void Train(int peakSample, double mSecToSecondSample, int sampleFreqHz) { // Clear old channel models channelsToSort = new List<int>(); channelModels.Clear(); trained = false; totalNumberOfUnits = 0; // Clear old unit dictionary unitDictionary = new Hashtable(); // Add the zero unit to the dictionary unitDictionary.Add(0, 0); // Clear the old unit2channel map unit2Channel = new Dictionary<int, int>(); // Set the inflection sample inflectionSample = peakSample; secondInflectionIndex = peakSample + (int)(sampleFreqHz * (mSecToSecondSample / 1000)); // Make sure we have something in the training matrix if (trainingSpikes.Buffer.Count == 0) { throw new InvalidOperationException("The training data set was empty"); } for (int i = 0; i < numberChannels; ++i) { // Current channel int currentChannel = i; // Get the spikes that belong to this channel List<SpikeEvent> spikesOnChan = trainingSpikes.Buffer.Where(x => x.Channel == currentChannel).ToList(); // Project channel data if (spikesOnChan.Count >= minSpikes) { // Train a channel model for this channel ChannelModel thisChannelModel = new ChannelModel(currentChannel, maxK, totalNumberOfUnits, pValue); // Project Data thisChannelModel.DoubleInflectProject(spikesOnChan.ToList(), inflectionSample, secondInflectionIndex); // Train Classifier thisChannelModel.Train(); // If there was a training failure (e.g. convergence) if (!thisChannelModel.trained) continue; // Note that we have to sort spikes on this channel channelsToSort.Add(currentChannel); // Update the unit dicationary and increment the total number of units for (int k = 1; k <= thisChannelModel.K; ++k) { unitDictionary.Add(totalNumberOfUnits + k, k); unit2Channel.Add(totalNumberOfUnits + k, i); } totalNumberOfUnits += thisChannelModel.K; // Add the channel model to the list channelModels.Add(thisChannelModel); } } // All finished trained = true; }