Skip to content

Instantly share code, notes, and snippets.

sales <- # (this is where we need data, but it's easy to find)
cumsales <- cumsum(sales)
time <- seq_along(sales)
tdelt <- (1:100)/length(time)
Bass <- sales ~ m * (((p+q)^2/p)*exp(-(p+q)*time))/(1+(q/p)*exp(-(p+q)*time))^2)
Bass.nls <- nls(formula = Bass, start=c(p=0.03,q=0.04,m=max(S)))
Bcoef <- coef(Bass.nls)
m <- Bcoef[1]
p <- Bcoef[2]
library(ggplot2)
library(reshape2)
library(RColorBrewer)
sales <- c(100,84,34,27,43,17,278,92,41,88,52,30,108,201,195,117,38,26,272,110,412,191,264,71,430,219,288,191,325,81)
cumsales <- c(1643,84,34,27,43,17,278,92,41,88,52,30,108,201,195,117,38,26,272,110,412,191,264,71,430,219,288,191,325,81)
cumsales <- cumsum(cumsales)
TSEP11 <- 1:30
Tdelt <- 1:180
Bass.nls <- nls(sales ~ M * ( ((P+Q)^2 / P) * exp(-(P+Q) * TSEP11) ) /(1+(Q/P)*exp(-(P+Q)*TSEP11))^2, start = list(M=max(cumsales), P=0.01, Q=0.3))
import logging
logging.basicConfig(format='%(asctime)s : %(Levelname)s : %(message)s', level=logging.INFO)
from gensim import corpora, models, similarities
stoplist = set('method,device,sysetem,apparatus,a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your'.split(','))
dictionary = corpora.Dictionary(line.lower().split() for line in open('abstracts.txt'))
stop_ids = [dictionary.token2id[stopword] for stopword in stoplist if stopword in dictionary.token2id]
once_ids = [tokenid for tokenid, docfreq in dictionary.dfs.it
import re, string
pattern=re.compile('[\W_]+')
f = open("C:\Users\graingec\spillovers\\abstracts\\abstracts.csv","rb")
abstracts = []
for line in f:
y = line.split(',',1)
if len(y)==2:
c = pattern.sub('',y[1].lower())
abstracts.append(c)
f.close()
import re, string
pattern=re.compile(r'[^a-zA-Z ]')
f = open("C:\Users\graingec\spillovers\\abstracts\\abstracts.csv","rb")
abstracts = []
for line in f:
y = line.split(',',1)
if len(y)==2:
abstracts.append(y[1])
f.close()
abstracts1 = []
import re, string
pattern=re.compile(r'[^a-zA-Z ]')
abstracts = []
with open("C:\Users\graingec\spillovers\\abstracts\\abstracts.csv","rb") as f:
for line in f:
y = line.split(',',1)
if len(y)==2:
abstracts.append(y[1])
abstracts1 = []
for i in abstracts:
with open("C:\Users\graingec\spillovers\\abstracts\orbis_patents_abstracts.csv","rb") as f:
with open("C:\Users\graingec\spillovers\\abstracts\\abstracts.csv","w") as f2:
f2.truncate()
for line in f:
y = line.split(',',1)
if len(y)==2:
c = y[1].replace(',','')
f2.write(y[0]+','+c)
with open('/Users/cigrainger/AeroFS/techproximity/shortabstracts.txt','rb') as f:
with open('/Users/cigrainger/AeroFS/techproximity/lemma.txt','w') as f2:
f2.truncate()
for line in f:
a = line.replace('\r\n','')
c = a.split(' ')
b = []
for i in c:
b.append(lmtzr.lemmatize(i))
a = ' '.join(b)
.libPaths("C:/Users/graingec/R/win-library")
library(dplyr)
library(tm)
library(lda)
library(wordcloud)
load('./data/abstractslang.rdata')
patents$APPLN_ABSTRACT_LG <- gsub("[^[:alnum:] ]", "",patents$APPLN_ABSTRACT_LG)
patents <- filter(patents,APPLN_ABSTRACT_LG == 'EN')
from nltk.stem.wordnet import WordNetLemmatizer
lmtzr = WordNetLemmatizer()
import re, string
pattern=re.compile(r'[^a-zA-Z ]')
def clean(x):
x = x.replace('<image>','')
x = pattern.sub('',x.lower())
x = x.replace('\r','')
x = x.replace('\n','')