<jupyter_start><jupyter_text>Example CP-APR with Numpy<jupyter_code>import scipy.io as spio
import numpy as np<jupyter_output><empty_output><jupyter_text>Load in the sample dataset:<jupyter_code>X = spio.loadmat('../data/test_data/subs.mat', squeeze_me=True)['values'] - 1
vals = spio.loadmat('../data/test_data/vals_count.mat', squeeze_me=True)['values']
X.shape<jupyter_output><empty_output><jupyter_text>We can also set the initial values of the latent factors:<jupyter_code># Initial factor values
M_init = {"Factors":{}, "Weights":[1,1]}
dim = 0
for key, values in spio.loadmat('../data/test_data/minit.mat', squeeze_me=True).items():
    if 'init_f' in key:
        M_init["Factors"][str(dim)] = values
        dim += 1
M_init<jupyter_output><empty_output><jupyter_text>Initilize:<jupyter_code>from pyCP_APR import CP_APR

cp_apr = CP_APR(n_iters=100, verbose=10, method='numpy')<jupyter_output>The history saving thread hit an unexpected error (OperationalError('attempt to write a readonly database')).History will not be written to the database.<jupyter_text>Take the CP-APR decomposition:<jupyter_code>result = cp_apr.fit(coords=X, values=vals, rank=2, Minit=M_init)
result<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13437757625721353, 'fraction_numerical': 0.009068425391591096, 'mean_word_length': 7.093333333333334, 'pattern_counts': {'":': 2, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '420446', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 464, 'n_tokens_neox': 451, 'n_words': 90, 'path': 'examples/CP-APR_Numpy.ipynb', 'repo_name': 'lanl/pyCP_APR', 'size': '1213'}