Skip to content

s0urceduty/Sourced_Neuron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Neurons

Sourced Neuron is a comprehensive Python library designed to advance computational neuroscience through a structured, multi-scale modeling framework inspired by Sourceduty’s science principles. The library integrates biophysical realism with adaptive systems modeling, allowing researchers to simulate neuronal dynamics ranging from single ion-channel kinetics to emergent network-level criticality. By combining deterministic conductance-based equations with stochastic input modeling and adaptive parameter tuning, Sourced Neuron provides a unified platform for constructing predictive neural simulations. The architecture is modular, enabling users to transition seamlessly between simplified integrate-and-fire abstractions and detailed multi-compartment Hodgkin–Huxley–style formulations. Each function is engineered to promote reproducibility, parameter transparency, and experimental alignment, making the library suitable for theoretical exploration, data-driven fitting, and hypothesis testing.

Neuron Models

Beyond individual neuron simulation, Sourced Neuron emphasizes network-level intelligence modeling, incorporating plasticity mechanisms such as Hebbian learning and spike-timing-dependent plasticity, dynamic energy consumption estimation, oscillatory analysis, and attractor state detection. Advanced analytical tools allow researchers to measure synchronization, entropy, and system criticality, bridging cellular biophysics with large-scale neural computation theory. The inclusion of parameter sweeps, sensitivity analysis, adaptive time-stepping, and optimization routines ensures that models remain both computationally efficient and biologically grounded. Designed for extensibility and research-grade simulation, Sourced Neuron aims to support neuroscientists, AI researchers, and computational modelers in building scalable, interpretable, and experimentally relevant models of neural systems.

Functions:

CORE LIFECYCLE & INITIALIZATION

  1. InitNeu(params): This function initializes neuron state variables and core parameters.
  2. SetWeight(w): Configures the initial synaptic weight values for incoming signals.
  3. SetBias(b): Establishes the threshold offset for the neuron's firing activation.
  4. GetState(): Retrieves the current electrochemical or mathematical state of the unit.
  5. ResetNeu(): Clears all temporal data and returns the neuron to a resting state.
  6. InitXavier(): Implements Xavier Initialization to keep signal variance consistent.
  7. InitHe(): Specifically scales weights for neurons using ReLU-based activations.
  8. CopyNeu(): Creates a deep copy of the neuron for genetic algorithms.
  9. SetID(name): Assigns a unique identifier to the neuron for tracking.
  10. CheckHealth(): Validates that all internal pointers and arrays are intact.
  11. CloneState(): Transfers the current potential and state to a new instance.
  12. Version(): Returns the current build version of the Sourced_Neuron lib.
  13. Shutdown(): Safely closes all data streams and saves the final state.
  14. MainLoop(): The master function that orchestrates all sub-processes.

SIGNAL PROCESSING & MATHEMATICS

  1. ProcInput(data): The primary function for receiving and scaling raw input vectors.
  2. SumSignals(): Performs the weighted summation of all current dendritic inputs.
  3. FireImpulse(): Executes the output transmission if the internal threshold is met.
  4. Integrate(dt): Performs temporal integration for continuous-time simulations.
  5. Leakage(rate): Simulates the natural decay of potential in a resting neuron.
  6. SynapticDelay(): Introduces a time lag between input reception and summation.
  7. ScaleInput(s): Multiplies all incoming signals by a constant scaling factor.
  8. BiasShift(s): Shifts the activation function along the x-axis.
  9. PulseSync(): Aligns the firing cycle with a global system clock.
  10. ParallelSum(): Uses multi-threading to speed up input summation.

ACTIVATION FUNCTIONS (NON-LINEARITY)

  1. ActReLU(x): Applies the Rectified Linear Unit activation to introduce non-linearity.
  2. ActSigmoid(x): Normalizes the output signal between a range of 0 and 1.
  3. ActTanh(x): Maps inputs to a range between -1 and 1 for zero-centered data.
  4. ActSoftmax(v): Converts a vector of values into a probability distribution.
  5. ActLeaky(x, a): A modified ReLU that prevents "dying neurons" by allowing a small gradient.
  6. ActELU(x, a): Exponential Linear Unit for faster learning and better noise handling.
  7. ActSwish(x): A self-gated activation function optimized for deep architectures.
  8. PulseWidth(t): Modulates the duration of an impulse in spiking neuron models.
  9. StepFunc(): A binary activation function for simple logic-gate simulations.
  10. LinearFunc(): Passes the input directly to output without transformation.
  11. SoftPlus(x): A smooth approximation of the ReLU function.
  12. MishAct(x): A self-regularized non-monotonic activation function.

LEARNING & OPTIMIZATION

  1. CalcError(tar): Measures the difference between the current output and target value.
  2. BackProp(err): Calculates the gradient of the loss function regarding weights.
  3. UpdWeight(lr): Adjusts internal weights based on the calculated gradient and learning rate.
  4. UpdBias(lr): Updates the bias parameter to refine the firing threshold over time.
  5. SetLR(rate): Dynamically adjusts the learning rate parameter for the optimizer.
  6. DecayLR(step): Reduces the learning rate over time to converge on a global minimum.
  7. ClipGrad(val): Prevents "exploding gradients" by capping the maximum gradient value.
  8. L1Reg(lambda): Adds Lasso regularization to encourage sparse weight matrices.
  9. L2Reg(lambda): Adds Ridge regularization to prevent excessively large weights.
  10. MomUpdate(v): Applies momentum to weight updates to bypass local minima.
  11. AdamOpt(): Implements the Adam Optimization logic.
  12. RMSProp(): Normalizes the gradient using a moving average of squared gradients.
  13. AdaGrad(): Adjusts learning rates based on the frequency of parameter updates.
  14. GetGrads(): Exports the current gradient values for external analysis.
  15. ResetGrads(): Zeroes out gradients before a new training iteration.
  16. SetTarget(t): Defines the ground-truth value for supervised learning.
  17. BatchSize(n): Sets how many inputs are processed before a weight update.

TOPOLOGY & CONNECTIVITY

  1. SynapsePrune(): Removes low-weight connections to optimize network efficiency.
  2. Inhibit(n2): Logic for one neuron to actively suppress the firing of another.
  3. Excite(n2): Logic for increasing the membrane potential of a target neuron.
  4. GetLayer(): Returns the index of the layer this neuron belongs to.
  5. BindTo(peer): Establishes a permanent synaptic link to a specific peer neuron.
  6. Unbind(peer): Severs the link between the neuron and a peer unit.
  7. GetSynCount(): Returns the total number of active synaptic connections.
  8. MapTopology(): Returns the spatial coordinates of the neuron in a 3D grid.
  9. DistanceTo(n): Calculates the Euclidean distance to another neuron.
  10. PruneOrphan(): Automatically deletes the neuron if it has no connections.

VALIDATION & METRICS

  1. CheckNaN(): Scans for "Not a Number" errors in the weight or output matrices.
  2. CheckLimit(): Ensures weights do not exceed pre-defined safety boundaries.
  3. PeakVoltage(): Records the highest potential reached during a cycle.
  4. FreqCheck(): Calculates the firing frequency over a set time window.
  5. LogLoss(): Calculates the logarithmic loss for classification tasks.
  6. MSELoss(): Computes the Mean Squared Error for regression tasks.
  7. HuberLoss(): Applies a loss function that is less sensitive to outliers.
  8. SetMaxWeight(): Clips weights to a specific maximum absolute value.
  9. SetMinWeight(): Sets a floor for weights to prevent dead connections.
  10. IsSaturated(): Detects if the neuron is stuck at the limits of its activation.
  11. VerifyArch(): Cross-references current params against the master architecture.
  12. CheckDep(): Verifies that required libraries like NumPy are installed.

DATA PERSISTENCE & I/O

  1. SaveModel(path): Serializes the current neuron parameters to a file.
  2. LoadModel(path): Restores weights and biases from a saved configuration file.
  3. LogActivity(): Records firing history and internal states for debugging.
  4. StreamIn(): Opens a data buffer for real-time sensor or stream input.
  5. FlushQueue(): Clears the input buffer to prevent data overflow.
  6. WatchWeight(): Attaches a listener to detect sudden changes in weight values.
  7. LatentState(): Accesses hidden variables not exposed to the output layer.
  8. ExportJSON(): Formats neuron data into a JSON string for web usage.
  9. ImportCSV(): Loads a weight matrix from a standard CSV file.
  10. TracePath(): Follows the signal flow through the neuron for auditing.

PERFORMANCE & HARDWARE

  1. DropOut(p): Randomly deactivates the neuron during training to prevent overfitting.
  2. NormBatch(): Standardizes the inputs across a batch to accelerate training.
  3. PlotNeuron(): Generates a visual representation of the neuron's current behavior.
  4. Refractory(p): Implements a "cool-down" period where the neuron cannot fire.
  5. SetPrecision(): Toggles between float32 and float16 for memory optimization.
  6. MutateWeight(): Introduces random noise into weights for evolutionary testing.
  7. Crossover(n2): Blends parameters with another neuron to create a "child" unit.
  8. IsFiring(): Boolean check to see if the neuron is currently in an active state.
  9. HeatMap(): Outputs a matrix of synaptic strengths for visualization.
  10. NoiseGen(std): Injects Gaussian noise to improve model robustness.
  11. AvgEnergy(): Estimates the computational cost or power usage of the neuron.
  12. EnableGPU(): Offloads mathematical operations to NVIDIA CUDA kernels.
  13. SharedMem(): Configures neurons to share a memory space for weights.
  14. UnitTests(): Runs a suite of internal tests to ensure functional integrity.
  15. Benchmark(): Measures the time taken to process 1,000,000 signals.

Prototype Lib

Sourced Neuron is a prototype PyPI library designed to provide a modular, research-oriented framework for computational neuron modeling grounded in Sourceduty’s science principles. As an experimental package, it integrates biophysical realism with scalable abstraction layers, allowing users to move seamlessly from single-compartment membrane models to multi-compartment morphologies and emergent network dynamics within a unified API. The library is structured around concise, high-efficiency functions that encapsulate membrane potential updates, ion channel kinetics, synaptic plasticity mechanisms (including Hebbian and spike-timing-dependent rules), stochastic input generation, and attractor-state analysis, while also supporting parameter sweeps, sensitivity testing, entropy estimation, and criticality detection. Designed for compatibility with standard scientific Python ecosystems (NumPy, SciPy, Matplotlib), Sourced Neuron emphasizes reproducibility, transparency of parameters, and computational efficiency, making it suitable for rapid prototyping, hypothesis testing, and educational exploration. As a prototype PyPI release, it focuses on clean architecture, extensibility, and clear documentation standards, encouraging community-driven expansion toward GPU acceleration, dataset integration, and interoperability with established neuroscience simulators while maintaining a lightweight core optimized for conceptual clarity and experimental modeling workflows.

Building Blocks

Building and developing with Sourceduty’s shared open-source Python functions creates a modular foundation for rapid experimentation, structured prototyping, and scalable software design. Because the functions are organized around reusable computational patterns, developers can combine them into larger systems without rewriting core logic, accelerating innovation across simulations, image processing, logic modeling, and scientific experimentation. This open structure encourages collaborative refinement, where improvements can compound over time into a powerful shared toolkit. Even beyond Python, these functions can serve as architectural references or be translated into other languages such as JavaScript, C++, or Rust, especially when supported by an AI chatbot that assists with syntax conversion, optimization, and debugging. In this way, Sourceduty’s function ecosystem becomes language-flexible and future-oriented, enabling developers to move fluidly between environments while maintaining a consistent computational framework.


https://chatgpt.com/g/g-675f752981348191a84d20f6f15cfb2b-neuron-modelling
https://sourceduty.com/