Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core.py #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions mofax/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,14 +1015,13 @@ def calculate_variance_explained(
),
Y=np.array(self.data[view][group]),
)
r2_df = r2_df.append(
{
r2_df = pd.concat([r2_df, pd.DataFrame(
[{
"View": view,
"Group": group,
"R2": r2,
"Factor": factor_name,
},
ignore_index=True,
}])], ignore_index=True
)
else:
r2 = calculate_r2(
Expand All @@ -1032,9 +1031,13 @@ def calculate_variance_explained(
W=np.array(self.expectations["W"][view][factor_indices, :]),
Y=np.array(self.data[view][group]),
)
r2_df = r2_df.append(
{"View": view, "Group": group, "R2": r2}, ignore_index=True
)
r2_df = pd.concat([r2_df, pd.DataFrame(
[{
"View": view,
"Group": group,
"R2": r2
}])], ignore_index=True
)

# use custom groups
# note that when calculating for a custom set of groups,
Expand Down Expand Up @@ -1073,24 +1076,27 @@ def calculate_variance_explained(
),
Y=np.array(data_view[group]),
)
r2_df = r2_df.append(
{
r2_df = pd.concat([r2_df, pd.DataFrame(
[{
"View": view,
"Group": group,
"R2": r2,
"Factor": factor_name,
},
ignore_index=True,
}])], ignore_index=True
)
else:
r2 = calculate_r2(
Z=np.array(z_custom[group][factor_indices, :]),
W=np.array(self.expectations["W"][view][factor_indices, :]),
Y=np.array(data_view[group]),
)
r2_df = r2_df.append(
{"View": view, "Group": group, "R2": r2}, ignore_index=True
)
r2_df = pd.concat([r2_df, pd.DataFrame(
[{
"View": view,
"Group": group,
"R2": r2
}])], ignore_index=True
)
return r2_df

def get_variance_explained(
Expand Down Expand Up @@ -1256,15 +1262,14 @@ def _get_factor_r2_null(
y = np.array(data_view[group])
a = np.sum((y - crossprod) ** 2)
b = np.sum(y ** 2)
r2_df = r2_df.append(
{
r2_df = pd.concat([r2_df, pd.DataFrame(
[{
"View": view,
"Group": group,
"Factor": f"Factor{factor_index+1}",
"R2": 1 - a / b,
"Iteration": i,
},
ignore_index=True,
}])], ignore_index=True
)

if return_full:
Expand Down