Skip to content

Instantly share code, notes, and snippets.

@Scriddie
Last active July 24, 2019 11:32
Show Gist options
  • Save Scriddie/7f6235d1d2c38630f620ee59abd44688 to your computer and use it in GitHub Desktop.
Save Scriddie/7f6235d1d2c38630f620ee59abd44688 to your computer and use it in GitHub Desktop.
mat_mult
# Calculate X * X
create table XtX (row_num int, col_num int, value int);
insert into XtX
select f1.col_num row_num
, f2.col_num col_num
, sum(f1.feature_value * f2.feature_value) value
from features f1
join features f2
on f1.row_num = f2.row_num
group by f1.col_num, f2.col_num;
#Calculate X * Y
create table XtY (row_num int, col_num int, value float);
insert into XtY
select f.col_num row_num
, l.col_num col_num
, sum(f.feature_value * l.label_value) value
from features f
join labels l
on f.row_num = l.row_num
group by f.col_num, l.col_num;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment