Documentation of source files (by LLM)

This commit is contained in:
2025-04-23 17:28:30 +02:00
parent c05e3e832c
commit 978383638b
14 changed files with 628 additions and 0 deletions

54
README_bond.md Normal file
View File

@ -0,0 +1,54 @@
# README_bond.md
## Overview
`bond.py` implements the Bond system, a key component of the Copycat system that manages the relationships between objects in strings. It handles the creation, evaluation, and management of bonds that represent meaningful connections between objects based on their properties and relationships.
## Core Components
- `Bond` class: Main class that represents a bond between objects
- Bond evaluation system
- Bond compatibility management
## Key Features
- Manages bonds between objects in strings
- Evaluates bond strength based on multiple factors
- Handles bond direction and category
- Supports bond flipping and versioning
- Manages bond compatibility and support
## Bond Components
- `source`: Source object of the bond
- `destination`: Destination object of the bond
- `category`: Category of the bond
- `facet`: Aspect of the bond
- `directionCategory`: Direction of the bond
- `sourceDescriptor`: Descriptor of the source object
- `destinationDescriptor`: Descriptor of the destination object
## Main Methods
- `updateInternalStrength()`: Calculate internal bond strength
- `updateExternalStrength()`: Calculate external bond strength
- `buildBond()`: Create and establish bond
- `breakBond()`: Remove bond
- `localSupport()`: Calculate local support
- `numberOfLocalSupportingBonds()`: Count supporting bonds
- `sameCategories()`: Compare bond categories
- `localDensity()`: Calculate local bond density
## Bond Types
- Letter category bonds
- Direction-based bonds
- Category-based bonds
- Flipped bonds
- Modified bonds
## Dependencies
- Requires `workspaceStructure` module
- Used by the main `copycat` module
## Notes
- Bonds are evaluated based on member compatibility and facet factors
- The system supports both same-type and different-type bonds
- Bonds can have direction categories (left, right)
- The system handles bond compatibility and support
- Bonds can be flipped to create alternative versions
- Local density and support factors influence bond strength

49
README_coderack.md Normal file
View File

@ -0,0 +1,49 @@
# README_coderack.md
## Overview
`coderack.py` implements the Coderack, a key component of the Copycat system that manages the execution of codelets (small, focused procedures) that drive the analogical reasoning process. It handles the posting, selection, and execution of codelets based on their urgency and the current state of the system.
## Core Components
- `Coderack` class: Main class that manages codelet execution
- Codelet management system
- Urgency-based codelet selection
## Key Features
- Manages a collection of codelets (small procedures)
- Implements urgency-based codelet selection
- Supports both top-down and bottom-up codelet posting
- Handles codelet execution and removal
- Manages rule, correspondence, description, and group proposals
## Codelet Types
- Breaker codelets
- Description codelets (top-down and bottom-up)
- Bond codelets (top-down and bottom-up)
- Group codelets (top-down and whole-string)
- Rule codelets (scout, strength-tester, builder, translator)
- Correspondence codelets (bottom-up and important-object)
- Replacement finder codelets
## Main Methods
- `post(codelet)`: Add a codelet to the coderack
- `chooseAndRunCodelet()`: Select and execute a codelet
- `postTopDownCodelets()`: Post codelets from activated slipnet nodes
- `postBottomUpCodelets()`: Post codelets based on workspace state
- `proposeRule()`: Create and post a rule proposal
- `proposeCorrespondence()`: Create and post a correspondence proposal
- `proposeDescription()`: Create and post a description proposal
- `proposeGroup()`: Create and post a group proposal
- `proposeBond()`: Create and post a bond proposal
## Dependencies
- Requires `codeletMethods` module
- Uses `bond`, `codelet`, `correspondence`, `description`, `group`, and `rule` modules
- Uses `logging` for debug output
- Uses `math` for urgency calculations
## Notes
- Codelets are organized by urgency bins
- The system maintains a maximum of 100 codelets
- Codelet selection is influenced by temperature and workspace state
- The system supports both deterministic and probabilistic codelet posting
- Codelet urgency is calculated based on various factors including conceptual depth

40
README_copycat.md Normal file
View File

@ -0,0 +1,40 @@
# README_copycat.md
## Overview
`copycat.py` is the core module of the Copycat system, implementing the main analogical reasoning algorithm. It coordinates the interaction between various components like the workspace, slipnet, coderack, and temperature system.
## Core Components
- `Copycat` class: Main class that orchestrates the analogical reasoning process
- `Reporter` class: Base class for defining different types of reporters (GUI, curses, etc.)
## Key Features
- Implements the main Copycat algorithm for analogical reasoning
- Manages the interaction between different system components
- Supports multiple interfaces (GUI, curses, command-line)
- Provides temperature-based control of the reasoning process
- Handles multiple iterations and answer collection
## Main Methods
- `run(initial, modified, target, iterations)`: Run the algorithm for a specified number of iterations
- `runGUI()`: Run the algorithm with graphical interface
- `run_forever(initial, modified, target)`: Run the algorithm continuously
- `runTrial()`: Run a single trial of the algorithm
- `step()`: Execute a single step of the algorithm
- `update_workspace(currentTime)`: Update all workspace components
## Dependencies
- Requires `coderack`, `randomness`, `slipnet`, `temperature`, and `workspace` modules
- Uses `pprint` for pretty printing results
- Optional GUI support through the `gui` module
## Usage
The module is typically used through one of the interface modules:
- `main.py` for command-line interface
- `gui.py` for graphical interface
- `curses_main.py` for terminal-based interface
## Notes
- The system uses a temperature-based control mechanism to guide the reasoning process
- Results include answer statistics, temperature, and time metrics
- The system supports both single-run and continuous operation modes
- The reporter system allows for flexible output handling

51
README_correspondence.md Normal file
View File

@ -0,0 +1,51 @@
# README_correspondence.md
## Overview
`correspondence.py` implements the Correspondence system, a key component of the Copycat system that manages the mapping relationships between objects in the initial and target strings. It handles the creation, evaluation, and management of correspondences that link objects based on their properties and relationships.
## Core Components
- `Correspondence` class: Main class that represents a mapping between objects
- Concept mapping system
- Correspondence strength evaluation
## Key Features
- Manages mappings between objects in initial and target strings
- Evaluates correspondence strength based on multiple factors
- Handles concept slippages and mappings
- Supports both direct and accessory concept mappings
- Manages correspondence compatibility and support
## Correspondence Components
- `objectFromInitial`: Object from the initial string
- `objectFromTarget`: Object from the target string
- `conceptMappings`: List of concept mappings
- `accessoryConceptMappings`: Additional concept mappings
- `flipTargetObject`: Flag for target object flipping
## Main Methods
- `updateInternalStrength()`: Calculate internal correspondence strength
- `updateExternalStrength()`: Calculate external correspondence strength
- `buildCorrespondence()`: Create and establish correspondence
- `breakCorrespondence()`: Remove correspondence
- `incompatible()`: Check correspondence compatibility
- `supporting()`: Check if correspondence supports another
- `internallyCoherent()`: Check internal coherence
## Concept Mapping Types
- Distinguishing mappings
- Relevant distinguishing mappings
- Bond mappings
- Direction mappings
- Symmetric mappings
## Dependencies
- Requires `conceptMapping`, `group`, `letter`, and `workspaceStructure` modules
- Uses `formulas` for mapping calculations
- Used by the main `copycat` module
## Notes
- Correspondences are evaluated based on concept mapping strength and coherence
- The system supports both direct and indirect concept mappings
- Correspondences can be incompatible with each other
- The system handles both letter and group correspondences
- Concept slippages are tracked and managed

37
README_cross_compare.md Normal file
View File

@ -0,0 +1,37 @@
# README_cross_compare.md
## Overview
`cross_compare.py` is a utility script that performs cross-comparison analysis between different problem sets in the Copycat system. It reads pickled problem sets and generates a comparison table showing how different variants of the Copycat system perform across various problems.
## Usage
Run the program from the terminal with the following command:
```bash
python cross_compare.py problem_set1.pkl problem_set2.pkl ...
```
### Arguments
- One or more pickled problem set files (`.pkl` files) to compare
## Output
The script generates a CSV file at `output/cross_compare.csv` containing:
- A comparison table of different Copycat variants
- Problem formulas and their results
- Cross-comparison metrics between different problem sets
## Features
- Reads multiple pickled problem sets
- Generates a cross-comparison table
- Organizes results by Copycat variants and formulas
- Exports results to CSV format
## Dependencies
- Requires the `copycat` module
- Uses `pickle` for reading problem sets
- Uses `collections.defaultdict` for data organization
- Uses `pprint` for pretty printing (though not actively used in the current code)
## File Structure
The output CSV file contains:
1. Headers: source, compare, source formula, compare formula
2. Problem descriptions in the format `A:B::C:_`
3. Results for each combination of variants and formulas

36
README_curses_main.md Normal file
View File

@ -0,0 +1,36 @@
# README_curses_main.md
## Overview
`curses_main.py` is a terminal-based interface for the Copycat program that provides a visual representation of the analogical reasoning process using the curses library. It offers a real-time view of the system's operation, including the workspace, slipnet, and coderack.
## Usage
Run the program from the terminal with the following command:
```bash
python curses_main.py abc abd ppqqrr
```
### Arguments
- `initial`: The first string in the analogy (e.g., "abc")
- `modified`: The second string showing the transformation (e.g., "abd")
- `target`: The third string to be transformed (e.g., "ppqqrr")
- `--focus-on-slipnet` (optional): Show the slipnet and coderack instead of the workspace
- `--fps` (optional): Target frames per second for the display
- `--seed` (optional): Provide a deterministic seed for the random number generator
## Features
- Interactive terminal-based interface
- Real-time visualization of the Copycat system's operation
- Option to focus on different components (workspace or slipnet/coderack)
- Configurable display speed
- Detailed logging to `./copycat.log`
## Dependencies
- Requires the `copycat` module
- Uses `curses` for terminal-based interface
- Uses `argparse` for command-line argument parsing
- Uses `logging` for output logging
## Notes
- The program can be interrupted with Ctrl+C
- The display is automatically cleaned up when the program exits
- The interface provides a more detailed view of the system's operation compared to the standard command-line interface

53
README_group.md Normal file
View File

@ -0,0 +1,53 @@
# README_group.md
## Overview
`group.py` implements the Group system, a key component of the Copycat system that manages the grouping of objects in strings. It handles the creation, evaluation, and management of groups that represent meaningful collections of objects based on their properties and relationships.
## Core Components
- `Group` class: Main class that represents a group of objects
- Group evaluation system
- Group description management
## Key Features
- Manages groups of objects in strings
- Evaluates group strength based on multiple factors
- Handles group descriptions and bond descriptions
- Supports group flipping and versioning
- Manages group compatibility and support
## Group Components
- `groupCategory`: Category of the group
- `directionCategory`: Direction of the group
- `facet`: Aspect of the group
- `objectList`: List of objects in the group
- `bondList`: List of bonds in the group
- `descriptions`: List of group descriptions
- `bondDescriptions`: List of bond descriptions
## Main Methods
- `updateInternalStrength()`: Calculate internal group strength
- `updateExternalStrength()`: Calculate external group strength
- `buildGroup()`: Create and establish group
- `breakGroup()`: Remove group
- `localSupport()`: Calculate local support
- `numberOfLocalSupportingGroups()`: Count supporting groups
- `sameGroup()`: Compare groups for equality
## Group Types
- Single letter groups
- Multi-letter groups
- Direction-based groups
- Category-based groups
- Length-based groups
## Dependencies
- Requires `description`, `workspaceObject`, and `formulas` modules
- Used by the main `copycat` module
## Notes
- Groups are evaluated based on bond association and length
- The system supports both single and multi-object groups
- Groups can have multiple descriptions and bond descriptions
- The system handles group compatibility and support
- Groups can be flipped to create alternative versions
- Length descriptions are probabilistically added based on temperature

31
README_gui.md Normal file
View File

@ -0,0 +1,31 @@
# README_gui.md
## Overview
`gui.py` is a graphical user interface implementation for the Copycat program. It provides a visual interface for running the analogical reasoning system, using matplotlib for visualization with a dark background theme.
## Usage
Run the program from the terminal with the following command:
```bash
python gui.py
```
### Arguments
- `--seed` (optional): Provide a deterministic seed for the random number generator
## Features
- Graphical user interface for the Copycat system
- Dark background theme for better visibility
- Real-time visualization of the system's operation
- Detailed logging to `./output/copycat.log`
## Dependencies
- Requires the `copycat` module
- Uses `matplotlib` for visualization
- Uses `argparse` for command-line argument parsing
- Uses `logging` for output logging
## Notes
- The GUI provides a more user-friendly interface compared to the command-line version
- Results are displayed both in the GUI and printed to the console
- The interface includes temperature and time information for each answer
- The dark background theme is optimized for better visibility of the visualization

41
README_main.md Normal file
View File

@ -0,0 +1,41 @@
# README_main.md
## Overview
`main.py` is the primary entry point for the Copycat program, which implements an analogical reasoning system. The program takes three strings as input and attempts to find an analogous transformation between them.
## Usage
Run the program from the terminal with the following command:
```bash
python main.py abc abd ppqqrr --iterations 10
```
### Arguments
- `initial`: The first string in the analogy (e.g., "abc")
- `modified`: The second string showing the transformation (e.g., "abd")
- `target`: The third string to be transformed (e.g., "ppqqrr")
- `--iterations` (optional): Number of times to run the case (default: 1)
- `--seed` (optional): Provide a deterministic seed for the random number generator
- `--plot` (optional): Generate a bar graph of answer distribution
- `--noshow` (optional): Don't display the bar graph at the end of the run
## Output
The program produces output in the following format:
```
iiijjjlll: 670 (avg time 1108.5, avg temp 23.6)
iiijjjd: 2 (avg time 1156.0, avg temp 35.0)
...
```
Where:
- The first number indicates how many times Copycat chose that string as its answer (higher means "more obvious")
- The last number indicates the average final temperature of the workspace (lower means "more elegant")
## Features
- Implements the Copycat analogical reasoning system
- Provides detailed logging to `./output/copycat.log`
- Can generate visualizations of answer distributions
- Saves results to `output/answers.csv`
## Dependencies
- Requires the `copycat` module
- Uses `argparse` for command-line argument parsing
- Uses `logging` for output logging

47
README_rule.md Normal file
View File

@ -0,0 +1,47 @@
# README_rule.md
## Overview
`rule.py` implements the Rule system, a key component of the Copycat system that manages the transformation rules used in analogical reasoning. It handles the creation, evaluation, and application of rules that describe how to transform strings based on their properties and relationships.
## Core Components
- `Rule` class: Main class that represents a transformation rule
- Rule evaluation system
- Rule translation and application system
## Key Features
- Defines transformation rules with facets, descriptors, categories, and relations
- Evaluates rule strength based on multiple factors
- Supports rule translation through concept slippages
- Handles string transformations based on rules
- Manages rule compatibility with correspondences
## Rule Components
- `facet`: The aspect of the object to change (e.g., length)
- `descriptor`: The property being changed
- `category`: The type of object being changed
- `relation`: The transformation to apply
## Main Methods
- `updateInternalStrength()`: Calculate rule strength
- `updateExternalStrength()`: Update external strength
- `activateRuleDescriptions()`: Activate rule-related concepts
- `buildTranslatedRule()`: Apply rule to target string
- `incompatibleRuleCorrespondence()`: Check rule-correspondence compatibility
- `ruleEqual()`: Compare rules for equality
## Rule Types
- Length-based rules (predecessor, successor)
- Character-based rules (predecessor, successor)
- Category-based rules
## Dependencies
- Requires `workspaceStructure` and `formulas` modules
- Uses `logging` for debug output
- Used by the main `copycat` module
## Notes
- Rules are evaluated based on conceptual depth and descriptor sharing
- Rule strength is calculated using weighted averages
- Rules can be translated through concept slippages
- The system supports both single-character and length-based transformations
- Rules can be incompatible with certain correspondences

51
README_slipnet.md Normal file
View File

@ -0,0 +1,51 @@
# README_slipnet.md
## Overview
`slipnet.py` implements the Slipnet, a key component of the Copycat system that represents the conceptual network of relationships between different concepts. It manages a network of nodes (concepts) and links (relationships) that are used in analogical reasoning.
## Core Components
- `Slipnet` class: Main class that manages the conceptual network
- Network of `Slipnode` objects representing concepts
- Network of `Sliplink` objects representing relationships
## Key Features
- Manages a network of conceptual nodes and their relationships
- Handles activation spreading between nodes
- Supports both slip and non-slip links
- Implements various types of relationships:
- Letter categories
- String positions
- Alphabetic positions
- Directions
- Bond types
- Group types
- Other relations
## Node Types
- Letters (a-z)
- Numbers (1-5)
- String positions (leftmost, rightmost, middle, single, whole)
- Alphabetic positions (first, last)
- Directions (left, right)
- Bond types (predecessor, successor, sameness)
- Group types (predecessorGroup, successorGroup, samenessGroup)
- Categories (letterCategory, stringPositionCategory, etc.)
## Link Types
- Slip links (lateral connections)
- Non-slip links (fixed connections)
- Category links (hierarchical connections)
- Instance links (specific examples)
- Property links (attributes)
- Opposite links (antonyms)
## Dependencies
- Requires `slipnode` and `sliplink` modules
- Used by the main `copycat` module
## Notes
- The network is initialized with predefined nodes and links
- Activation spreads through the network during reasoning
- Some nodes are initially clamped to high activation
- The network supports both hierarchical and lateral relationships
- The system uses conceptual depth to determine link strengths

51
README_temperature.md Normal file
View File

@ -0,0 +1,51 @@
# README_temperature.md
## Overview
`temperature.py` implements the Temperature system, a crucial component of the Copycat system that controls the balance between exploration and exploitation during analogical reasoning. It provides various formulas for adjusting probabilities based on the current temperature, which affects how the system makes decisions.
## Core Components
- `Temperature` class: Main class that manages the temperature system
- Multiple adjustment formulas for probability modification
- Temperature history tracking
## Key Features
- Manages temperature-based control of the reasoning process
- Provides multiple formulas for probability adjustment
- Supports temperature clamping and unclamping
- Tracks temperature history and differences
- Allows dynamic switching between adjustment formulas
## Adjustment Formulas
- `original`: Basic temperature-based adjustment
- `entropy`: Entropy-based adjustment
- `inverse`: Inverse weighted adjustment
- `fifty_converge`: Convergence to 0.5
- `soft_curve`: Soft curve adjustment
- `weighted_soft_curve`: Weighted soft curve
- `alt_fifty`: Alternative fifty convergence
- `average_alt`: Averaged alternative
- `best`: Working best formula
- `sbest`: Soft best formula
- `pbest`: Parameterized best
- `meta`: Meta-level adjustment
- `pmeta`: Parameterized meta
- `none`: No adjustment
## Main Methods
- `update(value)`: Update temperature value
- `clampUntil(when)`: Clamp temperature until specified time
- `tryUnclamp(currentTime)`: Attempt to unclamp temperature
- `value()`: Get current temperature
- `getAdjustedProbability(value)`: Get temperature-adjusted probability
- `useAdj(adj)`: Switch to different adjustment formula
## Dependencies
- Uses `math` for mathematical operations
- Used by the main `copycat` module
## Notes
- Temperature starts at 100.0 and can be clamped
- Lower temperatures encourage more conservative decisions
- Higher temperatures allow more exploratory behavior
- The system tracks average differences between adjusted and original probabilities
- Different adjustment formulas can be used for different reasoning strategies

45
README_tests.md Normal file
View File

@ -0,0 +1,45 @@
# README_tests.md
## Overview
`tests.py` is a test suite for the Copycat program that verifies the system's behavior across various analogical reasoning problems. It includes functionality to generate test distributions and run statistical tests on the results.
## Usage
Run the tests from the terminal with the following command:
```bash
python tests.py [filename] [unittest_args]
```
### Arguments
- `filename` (optional): Path to the test distributions file (default: '.distributions')
- `--generate`: Generate new test distributions
- `unittest_args` (optional): Additional arguments to pass to unittest
## Test Cases
The test suite includes the following problem sets:
1. `abc``abd` : `efg` → ?
2. `abc``abd` : `ijk` → ?
3. `abc``abd` : `xyz` → ?
4. `abc``abd` : `ijkk` → ?
5. `abc``abd` : `mrrjjj` → ?
Each problem is run for 30 iterations by default.
## Features
- Generates and saves test distributions
- Runs statistical tests using chi-squared analysis
- Supports custom test distribution files
- Integrates with Python's unittest framework
- Provides detailed test output and error messages
## Dependencies
- Requires the `copycat` module
- Uses `unittest` for test framework
- Uses `pickle` for saving/loading test distributions
- Uses `argparse` for command-line argument parsing
- Uses `copycat.statistics` for statistical analysis
## Notes
- The test distributions are saved in a pickle file
- The test suite can be run with or without generating new distributions
- Statistical tests use the `iso_chi_squared` function from the copycat statistics module
- The test suite is designed to be extensible for adding new test cases

42
README_workspace.md Normal file
View File

@ -0,0 +1,42 @@
# README_workspace.md
## Overview
`workspace.py` implements the Workspace, a central component of the Copycat system that manages the current state of the analogical reasoning process. It maintains the strings being compared, their objects, structures, and the overall state of the reasoning process.
## Core Components
- `Workspace` class: Main class that manages the reasoning workspace
- `WorkspaceString` objects for initial, modified, and target strings
- Collection of objects and structures (bonds, correspondences, etc.)
## Key Features
- Manages the three strings involved in the analogy (initial, modified, target)
- Tracks objects and their relationships
- Maintains structures like bonds, correspondences, and rules
- Calculates various unhappiness metrics
- Updates object values and structure strengths
- Manages the temperature-based control system
## Main Methods
- `resetWithStrings(initial, modified, target)`: Initialize workspace with new strings
- `updateEverything()`: Update all objects and structures
- `getUpdatedTemperature()`: Calculate current temperature
- `buildRule(rule)`: Add or replace the current rule
- `breakRule()`: Remove the current rule
- `buildDescriptions(objekt)`: Add descriptions to an object
## State Management
- Tracks total, intra-string, and inter-string unhappiness
- Maintains lists of objects and structures
- Manages the current rule and final answer
- Tracks changed objects and their correspondences
## Dependencies
- Requires `formulas`, `bond`, `correspondence`, `letter`, and `workspaceString` modules
- Used by the main `copycat` module
## Notes
- The workspace is the central state container for the reasoning process
- Unhappiness metrics guide the temperature-based control system
- The system supports both rule-based and correspondence-based reasoning
- Objects can have multiple descriptions and relationships
- The workspace maintains the final answer when reasoning is complete