This file contains 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 TYPE public.fraction CASCADE; | |
CREATE TYPE public.fraction AS | |
(z numeric(1000,0), | |
n numeric(1000,0)); | |
CREATE OR REPLACE FUNCTION frac_make_fraction(z NUMERIC(1000,0), n NUMERIC(1000,0)) | |
RETURNS fraction AS $$ | |
declare retval fraction; | |
BEGIN |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Nov 13 00:00:06 2016 | |
@author: ergo | |
""" | |
import select | |
import psycopg2 | |
import psycopg2.extensions | |
import threading |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Nov 13 00:00:06 2016 | |
@author: ergo | |
""" | |
import select | |
import psycopg2 | |
import psycopg2.extensions |
This file contains 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
from multicorn import ForeignDataWrapper | |
import urllib2 | |
class SoilGridsForeignDataWrapper(ForeignDataWrapper): | |
def __init__(self, options, columns): | |
super(SoilGridsForeignDataWrapper, self).__init__(options, columns) | |
def execute(self, quals, columns): |
This file contains 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
from multicorn import ForeignDataWrapper | |
import json | |
import urllib2 | |
class SoilGridsForeignDataWrapper(ForeignDataWrapper): | |
def __init__(self, options, columns): | |
super(SoilGridsForeignDataWrapper, self).__init__(options, columns) | |
This file contains 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
INSERT INTO plr_modules VALUES (0, 'library(e1071)'); | |
INSERT INTO plr_modules VALUES (1, 'mysvm <- readRDS("mysvm.RDS")'); |
This file contains 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 r_predict5(inp integer[]) | |
RETURNS SETOF text AS | |
$BODY$ | |
if (pg.state.firstpass) | |
{ | |
library(e1071) | |
mysvm <- readRDS("mysvm.rds") | |
assign("pg.state.firstpass", FALSE, env=.GlobalEnv) |
This file contains 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 r_predict4(inp integer) | |
RETURNS text AS | |
$BODY$ | |
result <- predict(mysvm, inp) | |
return(as.character(result[1:1])) | |
$BODY$ | |
LANGUAGE plr IMMUTABLE STRICT | |
COST 100; |
This file contains 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 r_predict3(inp integer) | |
RETURNS text AS | |
$BODY$ | |
if (pg.state.firstpass) | |
{ | |
library(e1071) | |
mysvm <- readRDS("mysvm.rds") | |
assign("pg.state.firstpass", FALSE, env=.GlobalEnv) |
This file contains 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
library(e1071) | |
data <- seq(1,10) | |
classes <- c('b','b','b','b','a','a','a','a','b','b') | |
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10) | |
saveRDS(mysvm, "mysvm.rds") |