Exemplo n.º 1
0
def doDirFix(dirList_, recurse_, deFuxDir_):
	# fold here ⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1
	print(f"""{CF.NEWLINE}checking directories for sanity, and fixing what I can, any items I can't repair will give an uncaught exception intentionally until I figure out the most common things to happen and a way to fix them""")
	print(f"""{CF.INDENTIN}this list should not contain anything except directories, other entries will be skipped (continue)""")
	print(f"""{CF.INDENTIN}it is assumed you are handing this function a "good" list, symlinks and so forth managed previously, it just does what it is supposed to do""")

	# 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥
	for thisEntry_ in dirList_:
		CF.whirl()

		# fix directory modes, make your list correctly, passing in here it is assumed to be accurate, and since the rest of the code is somewhat useless without this being accomplished, there is no option for this
		# and no trial run, nor error checking by intent, also the list is assumed to be reversed, no exceptions are caught
	# ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥
		# 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥
		if (thisEntry_[FO.ICANWRITE] is not True) or (thisEntry_[FO.ICANEXECUTE] is not True):
			FO.setMode(thisEntry_[FO.PATH], FO.CHMODDIR)
		# ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2 ⥣2

		# likewise I prefer to have the defuxing of directories always done, rather than an option
		# strip directory names down to DIRBLACKLIST = "[a-zA-Z0-9./]+"  # PCRE for directory characters to blacklist as it's result
		# this list is assumed to be reversed so that it operates from the deepest nesting out thus not invalidating the list
	# ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥ ⥣1⥥
		# 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥ 2⥥
		if thisEntry_[FO.BLACKTAIL] != "":
			FO.MOVE(thisEntry_[FO.PATH], thisEntry_[FO.WHITEFULLNAME])
Exemplo n.º 2
0
def rating_rec():
    if request.method == 'POST':
        idcode = request.form['idcode']
        rate = request.form['rate']
        filename = request.form['filename']
        CF.update_rating(idcode, filename, float(rate))
        return "1"
    else:
        return "-1"
Exemplo n.º 3
0
def __main__(argv_):
	# fold here ⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1⥥1
	CF.setOptions(argv_)

	if CF.OPTIONSDICT[CF.SPREADFILES] is True:
		FO.fixDest(CF.OPTIONSDICT[CF.DESTDIR], CF.OPTIONSDICT[CF.NUMSPREADDIRS])
	# print(f"""{CF.NEWLINE}{CF.outputOptionsStruct()}{CF.NEWLINE}|{CF.NEWLINE}""")
	# print(f"""OPTIONSHELPDICT as returned by outputHelp(["-h"]){CF.NEWLINE}{CF.outputHelp([])}""")
	# 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥ 1⥥
	thisDirList_ = FO.scanADir(CF.OPTIONSDICT[CF.SOURCEDIR], CF.OPTIONSDICT[CF.RECURSE])  # fixed by default, no option exists, the mode and defuxing of directories makes life so much easier for me 99.99% of the time
	thisDirList_.reverse()
	doDirListFix(thisDirList_, CF.OPTIONSDICT[CF.RECURSE], CF.OPTIONSDICT[CF.DEFUXTHINGS]):

	thisFileList_ = FO.scanADirForFiles(CF.OPTIONSDICT[CF.SOURCEDIR], CF.OPTIONSDICT[CF.RECURSE])
Exemplo n.º 4
0
    def find_movies(self):
        """
        Callback for "Find" button.
        Call the functions provided by the CF module to find recommended
        movies for a user. The returned result is shown in the list box
        """

        # Get user input User ID, make sure it is a valid number
        try:
            user_id = self.user_id_var.get()
        except ValueError:
            tkMessageBox.showerror("Input Error", "Please enter a number as User ID")
            return

        # clear the previous result
        self.result_list.delete(0, END)

        try:
            # call the function provided by the recommender system to get
            # the top recommended movies
            movies = ur.getmemovies(self.ratings, user_id, self.movie_names)

            # display the returned movies in the listbox
            for item in movies:
                self.result_list.insert(END, item)

        except IndexError:
            # Invalid user id that runs out of index of the data
            tkMessageBox.showerror("Input Error", "Invalid User ID")
        except Exception as e:
            # Handle any unexpected error thrown by the recommender system
            tkMessageBox.showerror("Unexpected Error", e)
Exemplo n.º 5
0
    def find_movies(self):
        # Get user input rating, make sure it is a valid number
        try:
            for var in self.rating_vars:
                r = var.get()
                if r < 1 or r > 5:
                    raise ValueError

        except ValueError:
            tkMessageBox.showerror("Input Error", "Please enter a number 1-5 for ratings")
            return

        # clear the previous result
        self.result_list.delete(0, END)

        try:
            # call the function provided by the recommender system to get
            # the top recommended movies

            for idx, var in zip(self.chosen_movies, self.rating_vars):
                self.ratings[USER_ID][idx] = var.get()

            movies = ur.recommend(self.ratings, USER_ID, self.sim_mat, NUM_MOVIES)

            # display the returned movies in the listbox
            for idx, rating in movies:
               self.result_list.insert(END, self.movie_names[idx + 1])

        except Exception as e:
            # Handle any unexpected error thrown by the recommender system
            tkMessageBox.showerror("Unexpected Error", e)
Exemplo n.º 6
0
def send_rec1(idcode):
    filename = CF.recommend(idcode)
    if os.path.isfile(os.path.join(app.config['REC_FOLDER'], filename)):
        response = make_response(send_from_directory(app.config['REC_FOLDER'], filename))
        response.headers['Content-Disposition'] = "attachment; filename=" + filename
        return response
    else:
        return "-2"
Exemplo n.º 7
0
def send_test(catenum):
    filename = CF.select_random_item_with_category(int(catenum))
    if os.path.isfile(os.path.join(app.config['REC_FOLDER'], filename)):
        response = make_response(send_from_directory(app.config['REC_FOLDER'], filename))
        response.headers['Content-Disposition'] = "attachment; filename=" + filename
        return response
    else:
        return "-2"
Exemplo n.º 8
0
def FILEDICT(fileName_):
    FILE_PARMS = [
        ("&F&", fileName_),
    ]

    dictToRtn_ = dict((x, y) for x, y in FILETUP)
    listToRtn_ = list((x) for x in FILE_POPENARGSTUP)
    listToRtn_ = CF.subParms(listToRtn_, FILE_PARMS)
    return listToRtn_, dictToRtn_
Exemplo n.º 9
0
def signup():
    if request.method == 'POST':
        name = request.form['name']
        tel = request.form['tel']
        face = request.files['face']
        user = User.query.filter_by(tel = tel).first()
        if(user):
            return "-2" # already exists
        result = engine.execute("select idcode from users order by idcode desc")
        idcode = result.fetchone()
        if(idcode == None):
            _id = 0
        else:
            _id = idcode['idcode'] + 1
        result.close()
        
        pn = os.path.join(app.config['FACE_FOLDER'], str(_id) + ".jpg")
        face.save(pn)
        ha = HairAnalyzer.HairAnalyzer(pn)
        img = ha.getImage()
        print(img.shape)
        face, eyes = ha.detectFace()
        if (len(eyes)<2):
            os.remove(pn)
            return "-3"

        area = ha.getHairArea(face)
        face_color=ha.getFaceColor(face,eyes)
        for i in range(img.shape[0]):
            for j in range(img.shape[1]):
                if area[i][j] == 1:
                    img[i][j]=face_color
        cv2.imwrite(os.path.join(app.config['FACE_FOLDER'], str(_id) + '_face.jpg'), img)

        facedata = img_face(_id, str(_id) +"_face.jpg")
        user = User(name,_id,tel)
        db_session.add(user)
        db_session.add(facedata)
        db_session.commit() 
        CF.add_user(str(_id), [], [])
        CF.show_DB()
        return str(_id)
    else:
        return "-1"
def get_CHFT(frtargs, cols_to_use=['T', 'n_b', 'Z', 'P_LW', 'P_HI', 'P_HeI', 'P_CVI']): #get cooling function from dataframe of input values (for use in calculations for isochronous binning)          
    '''
    Function to get cooling and heating functions from an input array
    Input:
    frtargs (dataframe/dataframe row): Row containing [temperature, baryon number density, metallicity, P_LW (RT_DISK_VAR_0), P_HI (RT_DISK_VAR_1), P_HeI (RT_DISK_VAR_2), P_CVI (RT_DISK_VAR_3)]
    cols_to_use (array): Names of the columns to use, can vary depending on setup (but default to 'T', 'n_b', 'Z', 'P_LW', 'P_HI', 'P_HeI', 'P_CVI')
    Outputs:
    cfun, hfun, c_time (floats): The cooling and heating functions, and the cooling time at those values
    '''
    cfargs=[frtargs[col] for col in cols_to_use]
    (cfun,hfun,ierr)=CF.frtgetcf(*cfargs) #call f2py function to get cooling and heating functions for these inputs
    c_time = k_boltz*cfargs[0]/(cfargs[1]*cfun) #(kB*T/n_b*Lambda(T))
    return [cfun, hfun, c_time] #Return the cooling and heating functions, and the cooling time
Exemplo n.º 11
0
def recommend():
    if request.method == "GET":
        token = request.args.get("token")
        if (token):
            cfItem = CF.CFItem()
            li = cfItem.recommend()
            # for i in li:
            #     print(i)
            #     tmp = RecommendItem()
            #     tmp.itemId = i[0]
            #     tmp.recommendlist = i[1:]
            #     data.append(tmp)
            print(li)
            return jsonify({'code': 200, 'data': li})
        else:
            return jsonify({'code': 203, 'data': 'params error'})
Exemplo n.º 12
0
    def _load_data(self):
        """
        Load ratings and movies data in the files whose names are set in
        variables RATINGS_DATA and MOVIES_DATA
        """
        # row: users  col: movies
        ratings = np.array(pd.read_csv(RATINGS_DATA, index_col=0))
        # use subset of movies
        self.ratings = ratings[:,:TOTAL_MOVIES]

        # movies information
        items = pd.read_csv(MOVIES_DATA, index_col=0)
        self.movie_names = items.Name[:TOTAL_MOVIES]

        # pre-compute the similarity matrix
        print "Computing ratings similarity matrix..."
        self.sim_mat = ur.getsim(self.ratings)
Exemplo n.º 13
0
def recommend():
    isbn = []
    isbn_num = {}
    conn = sqlite3.connect("Bookstore.db")
    cur = conn.cursor()
    cur.execute('select ISBN from book')

    rs = cur.fetchall()

    for line in rs:
        #print(line)
        isbn.append(line[0])
    print(isbn)
    i = 0
    for num in isbn:
        isbn_num[num] = i
        i += 1
    print(isbn_num)
    username = []
    username_num = {}
    cur.execute('select username from users')

    rs = cur.fetchall()

    for line in rs:
        #print(line)
        username.append(line[0])
    print(username)
    i = 0
    for num in username:
        username_num[num] = i
        i += 1
    print(username_num)
    evalution = []
    cur.execute('select username,ISBN,score from payrecord')

    rs = cur.fetchall()

    for line in rs:
        #print(line)
        evalution.append([line[0], line[1], line[2]])

    print(evalution)
    conn.commit()
    conn.close()

    data = np.full([len(username), len(isbn)], 0.0)
    for evale in evalution:
        try:
            data[username_num[evale[0]]][isbn_num[evale[1]]] = evale[2]
        except:
            print(evale)

    print(data)
    cf = CF.CF_knearest(k=6)
    m = []
    m = cf.fit(data)
    print(m)
    print(len(m))
    d = {}
    flag = 0
    for line in m:
        d[username[flag]] = [
            isbn[line[0]], isbn[line[1]], isbn[line[2]], isbn[line[3]],
            isbn[line[4]], isbn[line[5]]
        ]
        flag = flag + 1
    print(d)
    return d


#recommend()
Exemplo n.º 14
0
def main():
    """
	This function generates the various collab matrices as output.
	These matrices are later fed into rmse.py to obtain the various metrics associated with each method.
	collab_matrix1: Saved as collab_matrixCF.npy. Corresponds to normal Collaborative Filtering case.
	collab_matrix2: Saved as collab_matrixCFBaseline.npy. Corresponds to Baseline Collaborative Filtering case.
	collab_matrix3: Saved as collab_matrixSVD.npy. Corresponds to normal SVD case.
	collab_matrix4: Saved as collab_matrixSVD90.npy. Corresponds to SVD case with 90% energy retained.
	collab_matrix5: Saved as collab_matrixCUR.npy. Corresponds to normal CUR case.
	collab_matrix6: Saved as collab_matrixCUR90.npy. Corresponds to CUR case in which intermediate SVD retains 90% energy.
	"""
    pp = pprint.PrettyPrinter(indent=4)
    mID_names = {}
    number_of_items = 3952
    number_of_users = 6040
    top_k = 5
    mID_uID_rating = np.zeros(shape=(3952, 6040))
    f = open(os.getcwd() + '/ml-1m/ratings.dat', encoding='latin-1'
             )  #Reading file as input and storing it as 2D numpy array
    for line in f:
        mID_uID_rating[int(line.split('::')[1]) - 1][int(line.split('::')[0]) -
                                                     1] = line.split('::')[2]
    f.close()
    print("1**************"
          )  #This corresponds to the standard Collaborative Filtering Case
    training_data1, test_data1 = sample(3952, 6040, mID_uID_rating)
    collab_matrix1 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data1:
        collab_matrix1[i[0]][i[1]] = i[2]
    np.save("test_dataCF.npy", test_data1)
    collab_matrix1 = CF.normalise_collab_matrix(mID_uID_rating,
                                                number_of_items,
                                                number_of_users, top_k,
                                                collab_matrix1)
    np.save("collab_matrixCF.npy", collab_matrix1)
    print(
        "2**************"
    )  #This corresponds to the collaborative filtering with the baseline approach
    training_data2, test_data2 = sample(3952, 6040, mID_uID_rating)
    collab_matrix2 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data2:
        collab_matrix2[i[0]][i[1]] = i[2]
    np.save("test_dataCFBaseline.npy", test_data2)
    collab_matrix2 = CF_Baseline.compute(mID_uID_rating, number_of_items,
                                         number_of_users, top_k,
                                         collab_matrix2)
    np.save("collab_matrixCFBaseline.npy", collab_matrix2)
    print("3**************"
          )  #This corresponds to using SVD for approximating our ratings
    training_data3, test_data3 = sample(3952, 6040, mID_uID_rating)
    np.save("test_dataSVD.npy", test_data3)
    collab_matrix3 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data3:
        collab_matrix3[i[0]][i[1]] = i[2]
    U, Sig, V = svdModified.SVD1(collab_matrix3, False)
    SVDMat = np.matmul(np.matmul(U, Sig), V.transpose())
    np.save("collab_matrixSVD.npy", SVDMat)
    print(
        "4**************"
    )  #Here, we use SVD to approximate ratings. However, we remove concepts until 90% of the variation can still be explained
    training_data4, test_data4 = sample(3952, 6040, mID_uID_rating)
    np.save("test_dataSVD90.npy", test_data4)
    collab_matrix4 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data4:
        collab_matrix4[i[0]][i[1]] = i[2]
    U, Sig, V = svdModified.SVD1(collab_matrix4, True)
    SVDMat = np.matmul(np.matmul(U, Sig), V.transpose())
    np.save("collab_matrixSVD90.npy", SVDMat)
    print("5**************")  #Here, we use CUR to approximate ratings matrix
    training_data5, test_data5 = sample(3952, 6040, mID_uID_rating)
    np.save("test_dataCUR.npy", test_data5)
    collab_matrix5 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data5:
        collab_matrix5[i[0]][i[1]] = i[2]
    C, U, R = matrixFuncs.CUR(collab_matrix5, 1000, True)
    CURMat = (np.matmul((np.matmul(C, U)), R))
    np.save("collab_matrixCUR.npy", CURMat)
    print(
        "6**************"
    )  #CUR is used here. However, the SVD routine called from within CUR corresponds to the 90% energy case.
    training_data6, test_data6 = sample(3952, 6040, mID_uID_rating)
    np.save("test_dataCUR90.npy", test_data6)
    collab_matrix6 = np.zeros(shape=(number_of_items, number_of_users))
    for i in training_data6:
        collab_matrix6[i[0]][i[1]] = i[2]
    C, U, R = matrixFuncs.CUR(collab_matrix6, 1000, False)
    CURMat = (np.matmul((np.matmul(C, U)), R))
    np.save("collab_matrixCUR90.npy", CURMat)
Exemplo n.º 15
0
import Make_DB
import CF
import Main

Make_DB.make_DB()
L = [1,4,5,6,14,17,19,22,23,24,28,35,36,40,43,46,48,50,51,56,57,58,60,61,62,63,64,68,69,70,74,75,77,78,80,83,84,85]

for i in L:
    d = Main.check_hair_front("imgs_rec/" + "t" + str(i) +".jpg")
    print d
    CF.add_item("t"+ str(i) + ".jpg", d)

CF.show_DB()
Exemplo n.º 16
0
 def get_userCF(self, k=8):
     return CF.CF(k, 'item')
import CF

if __name__ == '__main__':
    c1 = CF.CF()
    c1.DelOldFiles(Str='_coco56')
    pass
Exemplo n.º 18
0
# Item base CF
# start = time.time()
# cf_item_base = CF.CFItemBase(train_data)
# end = time.time()
# print("time of training ItemBase CF model(s)", end - start)

# start = time.time()
# print("predicting rate with ItemBase CF model:", cf_item_base.predict(4, 200))
# end = time.time()
# print("time of predicting an item with ItemBase CF model(s)", end - start)

# no training
error = 0
error2 = 0
test_times = 200
cf = CF.CFUserBase(train_data)
start = time.time()
for i in range(test_times):
    rand_user = random.randint(0, user_count - 1)
    j = 0
    while train_data[rand_user, j] == 0:
        j += 1
    to_predict = train_data[rand_user, j]
    train_data[rand_user, j] = 0
    print("-----user_id-", rand_user, ", item_id-", j, "-----")
    print("origin rate:", to_predict)
    my_predict = cf.predict(rand_user, j)
    print("predicting rate with ItemBase CF model:", my_predict)
    error += abs(my_predict - to_predict)
    error2 += abs(3 - to_predict)
    train_data[rand_user, j] = to_predict
Exemplo n.º 19
0
from CF import *
from DataLoader import *
import numpy as np
from sklearn.model_selection import train_test_split

if __name__ == '__main__':
    filePath = "./data/ml-20m/ratings.csv"

    print("Loading data:")
    dataLoader = DataLoader(filePath)
    Y_data = dataLoader.readFile()
    print("Done!\n--------------------")

    y = np.zeros(Y_data.shape[0])
    rate_train, rate_test, y_train, y_test = train_test_split(Y_data,
                                                              y,
                                                              test_size=0.2)

    print("User-user Collaborative Filtering: ")
    cf = CF(rate_train, 5)
    cf.fit()
    # cf.print_recommendation()
    print("-------------------------")

    print("\nTESTING: \nComputing RMSE: ")
    cf.RMSE(rate_test)
Exemplo n.º 20
0
#
me_df = pd.read_csv("alarm_dat.csv", sep=",", index_col=0)
to_feed = np.array(me_df)
machine_list = list(me_df.index)
error_message = pd.read_csv("error_message.txt", sep=";")
errors = error_message.columns.values
simMat = json.load(open("simMat.txt"))

predictiveAlarmText1 = []
predictiveAlarmText2 = []
predictiveAlarmText3 = []
for i in machine_ids:
    machineId = i
    if machineId in machine_list:
        to_search = machine_list.index(machineId)
        rec_mes = ur.recommend(to_feed, to_search, simMat)
        mes_id_list = []
        for index in range(len(rec_mes)):
            o_id = rec_mes[index][0]
            mes_id_list.append(o_id)

        predictiveAlarmText1.append(errors[mes_id_list[0]])
        predictiveAlarmText2.append(errors[mes_id_list[1]])
        predictiveAlarmText3.append(errors[mes_id_list[2]])
    else:
        predictiveAlarmText1.append("Warning: no sufficient data for prediction.")
        predictiveAlarmText2.append("Warning: no sufficient data for prediction.")
        predictiveAlarmText3.append("Warning: no sufficient data for prediction.")

#
# data.out is used by DOME to link the
Exemplo n.º 21
0
                    type=str,
                    default=defaults['ClustalO_binary'],
                    help=argparse.SUPPRESS)
args = parser.parse_args()

if len(args.PDB) == 4:
    response = urllib2.urlopen(
        'https://www.rcsb.org/pdb/download/downloadFastaFiles.do?structureIdList={}&compressionType=uncompressed'
        .format(args.PDB))
    html = response.read()
    with open(HOME + '/uploads/{}.fasta'.format(args.PDB), "w") as f:
        f.write(html)
    with open(HOME + '/uploads/{}.fasta'.format(args.PDB), "r") as f:
        for line in f:
            if line.strip('\n') in ("<head>"):
                CF.cleanexit('PDB code not found.')
    args.FILENAME = '{}.fasta'.format(args.PDB)
else:
    CF.cleanexit('Your PDB code should be four letters long.')

if args.PDB != "None" and args.FILENAME != "None.fasta":
    message = 'Entered both a PDB code and a default file name. Using the PDB code, {}'.format(
        args.PDB)
    print(message)

programstart = time.time()
#If command line variables are specified, use those.
if len(sys.argv) > 1:
    MainProgram = CF.CF(settings=args)
    if args.PDB != "None":
        PDBProgram = PDB.PDB(settings=args)
Exemplo n.º 22
0
            'Maximum_Sequences' : "2000",
            'Blast_E_Value' : "1e-3",
            'Consensus_Threshold' : "0",#need to check if zero will give desired results. Might need to be 1
            'Consensus_Ratio' : "7",
            'Use_Complete_sequences' : "True",
            'Alignment_Iterations' : "1",
            'Maximum_Redundancy_Threshold' : "0.9",
            'Logging' : "False",
            'Keep_Temp_Files' : "False",
            'Chain' : 'A',
            'Angstrom' : "1",
            'Residue' : "0",
            'PDB_Name' : "None",
            }

settings=CF.setsettings(defaults,configfile)
#location of binaries to call
settings.BLAST=HOME+"/binaries/blastp"
settings.CDHIT=HOME+"/binaries/cd-hit"
settings.CLUSTAL=HOME+"/binaries/clustalo-1.2.4-Ubuntu-x86_64"

programstart = time.time()
#do checks of settings
warnings=[]
#Run CF checks to check all settings, return any warnings to warnings variable
warnings=warnings+CF.checks(settings).warnings
MainProgram=CF.CF(settings,warnings=warnings)
programend = time.time()
print '\nConsensus Finder Completed.'
os.rename(HOME+'/uploads/'+settings.FILENAME, HOME+'/completed/'+settings.FILENAME)
for i in MainProgram.output[:]:
 wordDir = r'D:\temp\project\01Tests\3-fightPlane\Classes'
 scrEnc = 'utf-8'
 desEnc = 'gbk'
 Type = ['.cpp', '.h', '.lrc']
 fn1 = FN.FN(wordDir)
 fn1.analyzeExtensions()
 c = 1
 error = []
 oldFiles = []
 for i in fn1.filesName:
     t = fn1.analyzeFN(i)
     if t[2] in Type:
         try:
             with open(t[0] + t[1] + t[2], 'r', encoding=scrEnc) as f:
                 text = f.read()
                 fileDir = t[0] + t[1] + t[2]
                 if (fileDir.find('_coco56_GBK_To_UTF-8') == -1):
                     print('c=', c, sep='')
                     print(t)
                     c += 1
                     oldFiles.append(fileDir)
                     newFileDir = t[0] + t[1] + '_coco56_GBK_To_UTF-8' + t[2]
                     if (not os.path.exists(newFileDir)):
                         with open(newFileDir, 'w', encoding=desEnc) as f2:
                             f2.write(text)
         except UnicodeDecodeError:
             error.append(t)
 cf = CF.CF(wordDir)
 cf.MoveOldFilesWithList(oldFiles)
 print(fn1.filesNum)
 pass
Exemplo n.º 24
0
import CF

cfItem = CF.CFItem()

for i in cfItem.recommend():
    print(i)
Exemplo n.º 25
0
def main():
    path_resources = 'dataset/pages.json'
    with open(path_resources) as f:
        resources = json.load(f)

    IRM_iter = 2  # which result of IRM iteration will be used
    th = .025  # threshold for UMF

    # 5-fold cross validation
    total = {
        'UMF': {
            'time': 0.,
            'f': 0.
        },
        'Random': {
            'time': 0.,
            'f': 0.
        },
        'CF': {
            'time': 0.,
            'f': 0.
        }
    }
    for fold in range(1, 5 + 1):

        path_train_relations = 'dataset/5-fold/train/%d_train.graph' % fold
        path_test_relations = 'dataset/5-fold/test/%d_test.graph' % fold
        path_dom0_assignments = 'dataset/5-fold/output/fold%d/dom0' % fold
        path_dom1_assignments = 'dataset/5-fold/output/fold%d/dom1' % fold

        # get an index of max-scored cluster assignment
        """
    path_IRM_status = 'dataset/5-fold/output/fold%d/status' % fold
    statuses = map(lambda l: l.rstrip().split(), open(path_IRM_status).readlines())
    scores = map(lambda status: float(status[6]), statuses)
    best_idx = scores.index(max(scores))
    """

        # get train relations
        lines = map(lambda l: l.rstrip().split(' '),
                    open(path_train_relations).readlines())
        trains = []
        for line in lines:
            trains.append((int(line[1]), int(line[2])))
        trains.sort()

        # get test relations
        lines = map(lambda l: l.rstrip().split(' '),
                    open(path_test_relations).readlines())
        tests = []
        for line in lines:
            tests.append((int(line[1]), int(line[2])))
        tests.sort()

        print '*** fold %d' % fold

        ### Tag-weights-based filstering
        # get cluster assignments for train data
        user_assignments = map(
            int,
            open(path_dom0_assignments).readlines()[IRM_iter].rstrip().split(
                ' '))
        page_assignments = map(
            int,
            open(path_dom1_assignments).readlines()[IRM_iter].rstrip().split(
                ' '))

        elapsed_time, f_measure = UMF(trains, tests, resources,
                                      user_assignments, page_assignments, th)
        total['UMF']['time'] += elapsed_time
        total['UMF']['f'] += f_measure
        print '[UMF] elapsed time: %.3f, F-measure: %.5f' % (elapsed_time,
                                                             f_measure)

        ### Random recommendation
        elapsed_time, f_measure = random_recommend(trains, tests, 333951)
        total['Random']['time'] += elapsed_time
        total['Random']['f'] += f_measure
        print '[Random (average of 5)] elapsed time: %.3f, F-measure: %.5f' % (
            elapsed_time, f_measure)

        ### User-based collaborative filtering ([n_recommends / n_user] tuples per a user)
        elapsed_time, f_measure = CF(trains, tests, 333951)
        total['CF']['time'] += elapsed_time
        total['CF']['f'] += f_measure
        print '[CF] elapsed time: %.3f, F-measure: %.5f' % (elapsed_time,
                                                            f_measure)

    print '*** Result (average of 5-folds)'
    for method, d in total.items():
        print '[%s] elapsed time: %.3f F-measure: %.5f' % (method, d['time'] /
                                                           5., d['f'] / 5.)
Exemplo n.º 26
0
 def get_itemCF(self, k=8):
     return CF.CF(k)
import CF

if  __name__ == '__main__':
    d1 = CF.CF(r'D:\0COCO\本科\大二下学期\2017新东方计算机')
    vType = ['.mp4', '.avi', '.vob', '.mkv', '.VOB', '.flv', '.wmv', '.mov', '.rmvb', '.ts']
    d1.MoveOldFiles(vType, Str = '_coco56')
    #d1.MoveOldFiles(Str = '_coco56')
    pass
Exemplo n.º 28
0
# Read out command line arguments
args = sys.argv

# Parse input

# If wrong return a bad request
if (len(args) < 3 or (len(args) > 1 and int(args[1]) <= 0 ) or (len(args) > 2 and args[2] == "")):
    print "BAD REQUEST"

# Else return the sentiment value
else:
    dataset = args[1]
    message = args[2]

    # Dataset ID
    print dataset
    
    print message
        
    Classifier = CF.Classifier()
    (success, sentiment, P_sentiment, certainty_sentiment) = Classifier.classify( message )

    if( sentiment == 0 or success ):
        print "True"
        print sentiment
        print certainty_sentiment
    else:
        print "False"
        for i in range(2):
            print 0