This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Test | |
| ismultiple(n, d) = n % d == 0 | |
| ismultiple12(n) = ismultiple(n, 12) | |
| @test ismultiple12(12) | |
| @test ismultiple12(36) | |
| @test !ismultiple12(13) | |
| @test isapprox(mean(ismultiple12.(1:10000)), 1/12; atol=0.001) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION add_noise(id STRING, score FLOAT64) | |
| RETURNS FLOAT64 | |
| AS ( | |
| (1 - (mod(abs(FARM_FINGERPRINT(id)), 10000) / 10000000)) * score | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION size(x FLOAT64, y FLOAT64) | |
| RETURNS STRING | |
| LANGUAGE js | |
| OPTIONS ( | |
| library=["gs://medium-bq-js-script/jstat.min.js"] | |
| ) | |
| AS | |
| r""" | |
| return Math.sqrt(jStat.sumsqrd([x, y])); | |
| """; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION size(x FLOAT64, y FLOAT64) | |
| RETURNS FLOAT64 | |
| LANGUAGE js AS r""" | |
| function euclidean(x, y) { | |
| return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) | |
| } | |
| return euclidean(x, y); | |
| """; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION size(x FLOAT64, y FLOAT64) | |
| RETURNS FLOAT64 | |
| LANGUAGE js AS r""" | |
| return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); | |
| """; | |
| select | |
| x | |
| ,y | |
| ,size(x, y) as js_distance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION multiply(x ANY TYPE, mult ANY TYPE) | |
| AS (x * mult); | |
| select | |
| x | |
| ,label | |
| ,multiply(x, 10) as new_x | |
| ,multiply(label, 10) as new_label | |
| ,multiply(label, 1.5) as float_label | |
| from ds.clusters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DROP FUNCTION ds.move_x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION ds.move_x(x FLOAT64, labelid INT64) | |
| RETURNS FLOAT64 | |
| AS (CASE WHEN labelid = 0 THEN x ELSE x * 100 END) | |
| OPTIONS (description="Make the x coordinate larger if the cluster id is 1.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE FUNCTION ds.move_x(x FLOAT64, labelid INT64) | |
| RETURNS FLOAT64 | |
| AS (CASE WHEN labelid = 0 THEN x ELSE x * 100 END); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TEMP FUNCTION move_x(x FLOAT64, labelid INT64) | |
| RETURNS FLOAT64 | |
| AS (CASE WHEN labelid = 0 THEN x ELSE x * 100 END); | |
| SELECT | |
| x | |
| ,move_x(x, label) AS new_x | |
| ,y | |
| ,label | |
| FROM |