Skip to content

Commit a4a7315

Browse files
authored
Update README.md
1 parent 92eda5c commit a4a7315

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The class `estimator.QILinearEstimator` provides three methods:
88
`fit`, `predict_x`, and `predict_b`. Once the `fit` method has been called using `A` and `b`,
99
`predict_x` can be used to sample entries of the estimated coefficient vector. Alternatively,
1010
`predict_b` can be used to sample entries of predictions corresponding to (un)observed
11-
target values. Examples can be found in the `tests` directory.
11+
target values.
1212

1313
The project setup is documented in [project_setup.md](project_setup.md).
1414

@@ -22,6 +22,41 @@ cd quantum-inspired-algorithms
2222
python -m pip install .
2323
```
2424

25+
## Example
26+
27+
```python
28+
import numpy as np
29+
from sklearn.datasets import make_low_rank_matrix
30+
from sklearn.model_selection import train_test_split
31+
from quantum_inspired_algorithms.estimator import QILinearEstimator
32+
33+
rng = np.random.RandomState(7)
34+
35+
# Generate example data
36+
m = 700
37+
n = 100
38+
A = make_low_rank_matrix(n_samples=m, n_features=n, effective_rank=3, random_state=rng, tail_strength=0.1)
39+
x = rng.normal(0, 1, A.shape[1])
40+
b = A @ x
41+
42+
# Create training and test datasets
43+
A_train, A_test, b_train, b_test = train_test_split(A, b, test_size=0.3, random_state=rng)
44+
45+
# Fit quantum-inspired model
46+
rank = 3
47+
r = 100
48+
c = 30
49+
n_samples = 100 # for Monte Carlo methods
50+
qi = QILinearEstimator(r, c, rank, n_samples, rng, sketcher_name="fkv")
51+
qi = qi.fit(A_train, b_train)
52+
53+
# Sample from b (vector of predictions)
54+
n_entries_b = 1000
55+
sampled_indices_b, sampled_b = qi.predict_b(A_test, n_entries_b)
56+
```
57+
58+
More examples can be found in the `tests` directory.
59+
2560
## Contributing
2661

2762
If you want to contribute to the development of quantum_inspired_algorithms,

0 commit comments

Comments
 (0)