remove unneeded files

This commit is contained in:
2025-07-07 00:38:00 +02:00
parent 62fa85a1b3
commit 0ce7f664b4
3 changed files with 0 additions and 200 deletions

View File

@@ -1,114 +0,0 @@
# Iterative Proposal Implementation
This implementation extends the existing local discretization framework with iterative convergence capabilities, following the analysis from `local_discretization_analysis.md`.
## Key Components
### 1. IterativeProposal Class
- **File**: `bayesnet/classifiers/IterativeProposal.h|cc`
- **Purpose**: Extends the base `Proposal` class with iterative convergence logic
- **Key Method**: `iterativeLocalDiscretization()` - performs iterative refinement until convergence
### 2. TANLdIterative Example
- **File**: `bayesnet/classifiers/TANLdIterative.h|cc`
- **Purpose**: Demonstrates how to adapt existing Ld classifiers to use iterative discretization
- **Pattern**: Inherits from both `TAN` and `IterativeProposal`
## Architecture
The implementation follows the established dual inheritance pattern:
```cpp
class TANLdIterative : public TAN, public IterativeProposal
```
This maintains the same interface as existing Ld classifiers while adding convergence capabilities.
## Convergence Algorithm
The iterative process works as follows:
1. **Initial Discretization**: Use class-only discretization (`fit_local_discretization()`)
2. **Iterative Refinement Loop**:
- Build model with current discretization (call parent `fit()`)
- Refine discretization using network structure (`localDiscretizationProposal()`)
- Compute convergence metric (likelihood or accuracy)
- Check for convergence based on tolerance
- Repeat until convergence or max iterations reached
## Configuration Parameters
- `max_iterations`: Maximum number of iterations (default: 10)
- `tolerance`: Convergence tolerance (default: 1e-6)
- `convergence_metric`: "likelihood" or "accuracy" (default: "likelihood")
- `verbose_convergence`: Enable verbose logging (default: false)
## Usage Example
```cpp
#include "bayesnet/classifiers/TANLdIterative.h"
// Create classifier
bayesnet::TANLdIterative classifier;
// Set convergence parameters
nlohmann::json hyperparams;
hyperparams["max_iterations"] = 5;
hyperparams["tolerance"] = 1e-4;
hyperparams["convergence_metric"] = "likelihood";
hyperparams["verbose_convergence"] = true;
classifier.setHyperparameters(hyperparams);
// Fit and use normally
classifier.fit(X, y, features, className, states, smoothing);
auto predictions = classifier.predict(X_test);
```
## Testing
Run the test with:
```bash
make -f Makefile.iterative test-iterative
```
## Integration with Existing Code
To convert existing Ld classifiers to use iterative discretization:
1. Change inheritance from `Proposal` to `IterativeProposal`
2. Replace the discretization logic in `fit()` method:
```cpp
// Old approach:
states = fit_local_discretization(y);
TAN::fit(dataset, features, className, states, smoothing);
states = localDiscretizationProposal(states, model);
// New approach:
states = iterativeLocalDiscretization(y, this, dataset, features, className, states_, smoothing);
TAN::fit(dataset, features, className, states, smoothing);
```
## Benefits
1. **Convergence**: Iterative refinement until stable discretization
2. **Flexibility**: Configurable convergence criteria and limits
3. **Compatibility**: Maintains existing interface and patterns
4. **Monitoring**: Optional verbose logging for convergence tracking
5. **Extensibility**: Easy to add new convergence metrics or stopping criteria
## Performance Considerations
- Iterative approach will be slower than the original two-phase method
- Convergence monitoring adds computational overhead
- Consider setting appropriate `max_iterations` to prevent infinite loops
- The `tolerance` parameter should be tuned based on your specific use case
## Future Enhancements
Potential improvements:
1. Add more convergence metrics (e.g., AIC, BIC, cross-validation score)
2. Implement early stopping based on validation performance
3. Add support for different discretization schedules
4. Optimize likelihood computation for better performance
5. Add convergence visualization and reporting tools

View File

@@ -1,20 +0,0 @@
# Makefile for testing iterative proposal implementation
# Include this in the main Makefile or use directly
# Test iterative proposal
test-iterative: buildd
@echo "Building iterative proposal test..."
cd build_Debug && g++ -std=c++17 -I../bayesnet -I../config -I/usr/local/include \
../test_iterative_proposal.cpp \
-L. -lbayesnet \
-ltorch -ltorch_cpu \
-pthread \
-o test_iterative_proposal
@echo "Running iterative proposal test..."
cd build_Debug && ./test_iterative_proposal
# Clean test
clean-test:
rm -f build_Debug/test_iterative_proposal
.PHONY: test-iterative clean-test

View File

@@ -1,66 +0,0 @@
// ***************************************************************
// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
// SPDX-FileType: SOURCE
// SPDX-License-Identifier: MIT
// ***************************************************************
#include <iostream>
#include <torch/torch.h>
#include <nlohmann/json.hpp>
#include "bayesnet/classifiers/TANLdIterative.h"
using json = nlohmann::json;
int main() {
std::cout << "Testing Iterative Proposal Implementation" << std::endl;
// Create synthetic continuous data
torch::Tensor X = torch::rand({100, 3}); // 100 samples, 3 features
torch::Tensor y = torch::randint(0, 2, {100}); // Binary classification
// Create feature names
std::vector<std::string> features = {"feature1", "feature2", "feature3"};
std::string className = "class";
// Create initial states (will be updated by discretization)
std::map<std::string, std::vector<int>> states;
states[className] = {0, 1};
// Create classifier
bayesnet::TANLdIterative classifier;
// Set convergence hyperparameters
json hyperparams;
hyperparams["max_iterations"] = 5;
hyperparams["tolerance"] = 1e-4;
hyperparams["convergence_metric"] = "likelihood";
hyperparams["verbose_convergence"] = true;
classifier.setHyperparameters(hyperparams);
try {
// Fit the model
std::cout << "Fitting TANLdIterative classifier..." << std::endl;
classifier.fit(X, y, features, className, states, bayesnet::Smoothing_t::LAPLACE);
// Make predictions
torch::Tensor X_test = torch::rand({10, 3});
torch::Tensor predictions = classifier.predict(X_test);
torch::Tensor probabilities = classifier.predict_proba(X_test);
std::cout << "Predictions: " << predictions << std::endl;
std::cout << "Probabilities shape: " << probabilities.sizes() << std::endl;
// Generate graph
auto graph = classifier.graph();
std::cout << "Graph nodes: " << graph.size() << std::endl;
std::cout << "Test completed successfully!" << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}