Complete API Reference for P9ML Membrane Computing System Components
- P9MLMembrane API
- P9MLNamespace API
- P9MLCognitiveKernel API
- P9MLEvolution API
- P9MLVisualizer API
- P9MLTest API
- Factory Methods
Creates a new P9ML membrane wrapper around a neural network module.
Parameters:
module(nn.Module): The neural network module to wrapmembrane_id(string, optional): Unique identifier for the membrane
Returns: P9MLMembrane instance
Example:
local linear = nn.Linear(784, 128)
local membrane = nn.P9MLMembrane(linear, 'feature_extractor')Adds an evolution rule to the membrane.
Parameters:
rule(P9MLEvolutionRule): Evolution rule instance
Returns: void
Example:
local rule = nn.P9MLEvolutionFactory.createGradientEvolution(0.01, 0.9)
membrane:addEvolutionRule(rule)Enables quantization aware training for the membrane.
Parameters:
bits(number): Target quantization bits (typically 8, 16)scale_factor(number): Initial scale factor for quantization
Returns: void
Example:
membrane:enableQuantization(8, 0.1)Performs forward pass through the membrane with cognitive enhancements.
Parameters:
input(Tensor): Input tensor
Returns: Tensor - Enhanced output
Performs backward pass through the membrane with evolution.
Parameters:
input(Tensor): Input tensor from forward passgradOutput(Tensor): Gradient with respect to output
Returns: Tensor - Gradient with respect to input
Returns comprehensive membrane information.
Returns: Table with fields:
membrane_id(string): Membrane identifiertensor_vocabulary(table): Analyzed tensor shapesevolution_rules(table): Applied evolution rulesqat_state(table): Quantization statewrapped_module(string): Type of wrapped module
Example:
local info = membrane:getMembraneInfo()
print(string.format("Membrane %s has %d vocabulary entries",
info.membrane_id, #info.tensor_vocabulary))Creates a new P9ML namespace for distributed coordination.
Parameters:
namespace_id(string, optional): Unique identifier for the namespace
Returns: P9MLNamespace instance
Registers a membrane for distributed computation.
Parameters:
membrane(P9MLMembrane): Membrane to registerregistration_key(string, optional): Custom registration key
Returns: string - Registration key used
Example:
local key = namespace:registerMembrane(membrane, 'input_processor')Orchestrates computation across registered membranes.
Parameters:
input(Tensor): Input datacomputation_graph(table): Computation graph specification
Returns: Table - Computation results
Applies meta-learning across the namespace.
Returns: void
Returns current namespace state and statistics.
Returns: Table with fields:
registered_count(number): Number of registered membraneshypergraph_stats(table): Hypergraph topology statisticsmeta_learning_stats(table): Meta-learning performance
Example:
local state = namespace:getNamespaceState()
print(string.format("Namespace has %d membranes and %d hypergraph nodes",
state.registered_count, state.hypergraph_stats.nodes))Creates a new cognitive kernel for hypergraph-based reasoning.
Returns: P9MLCognitiveKernel instance
Adds a tensor shape as a lexeme to the cognitive lexicon.
Parameters:
tensor_shape(table): Tensor shape as array (e.g., {784, 128})membrane_id(string): Associated membrane identifiercontext(table, optional): Contextual information
Returns: string - Lexeme identifier
Example:
local lexeme_id = kernel:addLexeme({784, 128}, 'feature_layer', {
layer_type = 'linear',
position = 'input'
})Adds a membrane as a grammar rule in the production system.
Parameters:
membrane_info(table): Membrane information fromgetMembraneInfo()rule_type(string): Type of grammar rule
Returns: string - Grammar rule identifier
Generates a unified gestalt tensor field from all components.
Returns: Tensor - Gestalt field representation
Resolves the frame problem using nested membrane embeddings.
Parameters:
context(table): Problem contextquery_tensor(Tensor): Query tensor for resolution
Returns: Table with fields:
nested_contexts(table): Resolved nested contextscognitive_coherence(number): Coherence measureresolution_path(table): Solution path
Returns current cognitive state and statistics.
Returns: Table with fields:
lexemes_count(number): Number of lexemesgrammar_rules_count(number): Number of grammar rulesgestalt_coherence(number): Current gestalt coherenceproduction_categories(table): Production rule categories
Creates a new evolution rule.
Parameters:
rule_type(string): Type of evolution ruleparameters(table): Rule parameters
Returns: P9MLEvolutionRule instance
Applies the evolution rule to membrane objects.
Parameters:
membrane_objects(table): Table of membrane objects
Returns: void
Returns evolution rule statistics.
Returns: Table with fields:
rule_type(string): Rule typeactivation_count(number): Number of activationssuccess_rate(number): Success rate (0-1)adaptation_history(table): Adaptation history
Generates a complete system visualization.
Parameters:
namespace(P9MLNamespace): Namespace instancekernel(P9MLCognitiveKernel): Cognitive kernel instance
Returns: string - ASCII diagram
Generates Graphviz DOT format for system visualization.
Parameters:
namespace(P9MLNamespace): Namespace instancekernel(P9MLCognitiveKernel): Cognitive kernel instance
Returns: string - DOT format string
Generates complete visualization suite.
Parameters:
namespace(P9MLNamespace): Namespace instancekernel(P9MLCognitiveKernel): Cognitive kernel instanceoutput_dir(string): Output directory path
Returns: Table - Paths to generated files
Runs the complete P9ML test suite.
Returns: boolean - True if all tests pass
Tests membrane creation and basic functionality.
Returns: boolean - Test result
Tests namespace operations and coordination.
Returns: boolean - Test result
Tests cognitive kernel functionality.
Returns: boolean - Test result
Tests evolution rule application and adaptation.
Returns: boolean - Test result
Creates a gradient-based evolution rule.
Parameters:
learning_rate(number): Learning rate parametermomentum(number): Momentum parameter
Returns: P9MLEvolutionRule instance
Example:
local rule = nn.P9MLEvolutionFactory.createGradientEvolution(0.01, 0.9)Creates an adaptive quantization rule.
Parameters:
target_bits(number): Target quantization bitsscale_factor(number): Initial scale factor
Returns: P9MLEvolutionRule instance
Creates a cognitive adaptation rule.
Parameters:
threshold(number): Cognitive thresholdstrength(number): Adaptation strength
Returns: P9MLEvolutionRule instance
-- 1. Create membrane-wrapped layers
local membrane1 = nn.P9MLMembrane(nn.Linear(784, 128), 'input_layer')
local membrane2 = nn.P9MLMembrane(nn.Linear(128, 10), 'output_layer')
-- 2. Add evolution rules
membrane1:addEvolutionRule(nn.P9MLEvolutionFactory.createGradientEvolution(0.01, 0.9))
membrane2:enableQuantization(8, 0.1)
-- 3. Create cognitive infrastructure
local namespace = nn.P9MLNamespace('mnist_classifier')
local kernel = nn.P9MLCognitiveKernel()
-- 4. Register and configure
namespace:registerMembrane(membrane1, 'feature_extractor')
namespace:registerMembrane(membrane2, 'classifier')
kernel:addLexeme({784, 128}, 'feature_transformation')
kernel:addLexeme({128, 10}, 'classification')-- Create complex cognitive network
local namespace = nn.P9MLNamespace('cognitive_system')
local kernel = nn.P9MLCognitiveKernel()
-- Build network with multiple membranes
local membranes = {}
for i = 1, 5 do
local membrane = nn.P9MLMembrane(nn.Linear(128, 128), 'layer_' .. i)
membrane:addEvolutionRule(nn.P9MLEvolutionFactory.createCognitiveAdaptation(0.5, 0.1))
namespace:registerMembrane(membrane)
kernel:addLexeme({128, 128}, 'layer_' .. i)
table.insert(membranes, membrane)
end
-- Apply meta-learning and generate visualizations
namespace:applyMetaLearning()
local gestalt = kernel:generateGestaltField()
local visualizations = nn.P9MLVisualizer.generateVisualizationSuite(namespace, kernel, './viz')Most P9ML methods include error checking and will throw descriptive error messages for:
- Invalid tensor shapes
- Incompatible module types
- Missing required parameters
- Namespace registration conflicts
- Evolution rule application failures
Always wrap P9ML operations in appropriate error handling:
local success, err = pcall(function()
local membrane = nn.P9MLMembrane(invalid_module, 'test')
end)
if not success then
print("P9ML Error: " .. err)
end- Memory Usage: P9ML adds cognitive state overhead (~10-20% of base model)
- Computation: Evolution rules add minimal overhead (~1-5% per forward pass)
- Quantization: Can reduce memory usage by 50-75% with minimal accuracy loss
- Cognitive Operations: Gestalt field generation is O(n²) in number of lexemes