Comments (3)
Hi @MarMarhoun and thanks for reaching out.
I run the code snippet you sent on my side and it appears that the data
tensor you are trying to use as an input for the SB algorithm has a shape (252, 6)
.
For SB to work, the input matrix you provide must be square, i.e. it must have 2 dimensions and both must be the same. The problem you encountered comes from the difference between the two dimensions of the matrix.
Hope this could help.
All the best!
from simulated-bifurcation-algorithm.
Greetings @bqth29,
Yes, I know this issue is there any way I can solve this issue?
I tried the following code to run the simulated bifurcation algorithm. However, I received an issue during the implementation.
Here is the code:
!pip install yfinance
!pip install plotly
!pip install tqdm
!pip install numpy
!pip install pandas
!pip install simulated-bifurcation
!pip install deap
!pip install plotly_express
import yfinance as yf
import torch
import random # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import yfinance as yf
import matplotlib.pyplot as plt
import json
import numpy as np
import simulated_bifurcation as sb
def get_data(asset_name, period='1y', interval='1d'):
data = yf.download(tickers=asset_name, period=period, interval=interval)
return data
def optimize_sb(matrix, **kwargs):
sb.set_env(time_step=.1, pressure_slope=.01, heat_coefficient=.06)
best_vector, best_value = sb.maximize(matrix, **kwargs)
return best_vector, best_value
if __name__ == "__main__":
asset_name = 'AAPL'
data = get_data(asset_name)
matrix = torch.tensor(data.to_numpy())
agents = 100
max_steps = 10000
sampling_period = 30
convergence_threshold = 50
device = 'cuda' # To enable the GPU
best_vector, best_value = optimize_sb(matrix, agents=agents, device=device,
max_steps=max_steps, sampling_period=sampling_period, ballistic= True,
convergence_threshold=convergence_threshold, use_window=True, heated=True, best_only=True)
Here is the issue:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-efec6dd548a5> in <cell line: 2>()
1 sb.set_env(time_step=.1, pressure_slope=.01, heat_coefficient=.06)
----> 2 best_vector, best_value = sb.maximize(matrix, agents=100, device='cuda',
3 max_steps=10000, sampling_period=30, ballistic= True,
4 convergence_threshold=50, use_window=True, heated=True, best_only=True)
6 frames
/usr/local/lib/python3.10/dist-packages/simulated_bifurcation/polynomial/base_multivariate_polynomial.py in __check_square_matrix(matrix)
252 raise ValueError(f"Matrix requires two dimension, got {matrix.ndim}.")
253 if matrix.shape[0] != matrix.shape[1]:
--> 254 raise ValueError("Matrix must be square.")
255
256 def __check_vector_shape(self, vector: torch.Tensor) -> None:
ValueError: Matrix must be square.
from simulated-bifurcation-algorithm.
Hi @MarMarhoun,
It appears that your input matrix does not suit the SB algorithm because it is not square. Could you explain us what your code is trying to achieve to see if we can apply some operations to said matrix to make it square and compatible with SB?
All the best!
from simulated-bifurcation-algorithm.
Related Issues (10)
- [BUG] MemoryError when creating an instance of IntegerPolynomial for integers with a large number of bits HOT 1
- [ENH] Add Integer Portfolio Optimization HOT 7
- [BUG] Algorithm performance dwindles when the number of agents increases
- TypeError: 'type' object is not subscriptable when importing simulated_bifurcation HOT 2
- [ENH] Replace `logging.warning` with `warnings.warn`
- RuntimeError: expected m1 and m2 to have the same dtype, but got: double != float HOT 1
- SB Optimizer computation dtype v. Model dtype
- RuntimeError: expected scalar type Double but found Float HOT 2
- [ENH] Speed up computation when agents have converged
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simulated-bifurcation-algorithm.