<jupyter_start><jupyter_text>=============================Create a model from scratch, and then update it with new subject data=============================In this example, we will simulate a model and update the model with the new data.First, we'll load in some example locations. Then, we will simulatecorrelational structure (a toeplitz matrix) to impose on our simulated data.We simulate 3 brain objects by sampling 10 locations from example_locs andcreate a model from these brain objects. Then, we will simulate an additionalbrain object and use the model.update method to update an existing model withnew data.<jupyter_code># Code source: <NAME> & <NAME>
# License: MIT

# import libraries
import matplotlib.pyplot as plt
import supereeg as se


# simulate 100 locations
locs = se.simulate_locations(n_elecs=100)

# simulate correlation matrix
R = se.create_cov(cov='toeplitz', n_elecs=len(locs))

# simulate brain objects for the model that subsample n_elecs for each synthetic patient
model_bos = [se.simulate_model_bos(n_samples=1000, sample_rate=1000, locs=locs, sample_locs=10, cov='toeplitz')
             for x in range(3)]

# create the model object
model = se.Model(data=model_bos, locs=locs, n_subs=3)
model.plot_data()

# brain object locations subsetted
sub_locs = locs.sample(10).sort_values(['x', 'y', 'z'])

# simulate a new brain object using the same covariance matrix
bo = se.simulate_bo(n_samples=1000, sample_rate=1000, locs=sub_locs, cov='toeplitz')

# update the model
new_model = model.update(bo, inplace=False)

# initialize subplots
f, (ax1, ax2) = plt.subplots(1, 2)
f.set_size_inches(14,6)

# plot it and set the title
model.plot_data(ax=ax1, show=False, yticklabels=False, xticklabels=False, cbar=True, vmin=0, vmax=1)
ax1.set_title('Before updating model: 3 subjects total')

# plot it and set the title
new_model.plot_data(ax=ax2, show=False, yticklabels=False, xticklabels=False, cbar=True, vmin=0, vmax=1)
ax2.set_title('After updating model: 4 subjects total')

plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12081513828238719, 'fraction_numerical': 0.023289665211062592, 'mean_word_length': 6.085910652920962, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '150406', 'license': 'MIT', 'n_tokens_mistral': 712, 'n_tokens_neox': 662, 'n_words': 220, 'path': 'docs/auto_examples/plot_update_model.ipynb', 'repo_name': 'tmuntianu/supereeg', 'size': '2072'}