Day_54-55

news2024/9/20 18:54:05

目录

Day_54基于 M-distance 的推荐

一. 关于M-distance 的推荐

        1. 基本数据说明

        2. 推荐系统的算法过程

        3. 简单思考

二. 代码复现

        1. 数据导入

        2. 代码的初始化

        3. 核心代码

        3.1 基础数据的构建

        3.2 leave-out-leave测试

        3.3 误差计算

Day_55基于 M-distance 的推荐 (续)

一. 解法思路

二. 运行结果

三. 补充54天的代码:


Day_54基于 M-distance 的推荐

一. 关于M-distance 的推荐

        1. 基本数据说明

        首先我们要明确什么是M-distance 的推荐,其本质和kNN算法有异曲同工之妙,kNN算法是根据邻居的种类来判断测试样本的种类,那么同样的道理,M-distance推荐也是根据邻居的属性来确定样本的属性。那该怎么做呢?

        首先我们根据样本的数据入手:输入的数据是100000行3列的矩阵,这个矩阵是稀疏矩阵,我们将原本的稀疏矩阵还原为普通矩阵更好理解如图G1所示。这100000×3的矩阵的3列分别代表“①评分人”,“②评分的事物”,“③这个人对这个事物打多少分”,这个0分表示不是这个人对这个项目打0分,而是这个人没有对这个项目打分(一个人不可能看完所有的项目)。我们知道同一个人是不是可以对不同的事物打分?不同的人是不是可以对同一个事物打分?同样的道理一个人对于不同的项目有不同的分数(一行数据所示),同一个项目对于不同的人有不同的分数(一列数据所示)(如图G1所示)

图G1

        现在的问题是:若我知道这里面的所有数据99999个数据,还有一个数据不知道多少分,那么我们该怎么样估计这个分数?

        2. 推荐系统的算法过程

        这里的估计过程和kNN算法有所不同,kNN算法直接根据周围点的远近即可估计(一维),但是这里我们有两个量(二维),第i个人对第j个项目的评分,所以我们不能简单的只考虑行或者列而是要将两者都考虑进来。

        首先我们算出每个项目的平均评分情况(将每个项目对应的列的数据相加(只加非0部分的数据),再除以这列的非0的个数。得到的结果如上图G1ave所示),接着我们设置阈值参数\Delta,然后将ave的每一个值与样本(样本是第i行第j列)对应的ave的j列的值作比较,若在ave[ j ]\pm \Delta的范围内,则记录对应的项目的列(2,5) (这里要把0除开,我自己画的矩阵参数不是太好可以参考——博客),最后根据我们所得到第i行所记录项目的列的平均数[(i,2)+(i,5)]/2,估计样本的值。

        3. 简单思考

        其实M-distance 的推荐也还是一个估计的过程,相较于kNN,只不过估计考虑的参数变多了(由以前的一维变为二维),但是思想仍然没有改变。它的思维过程有点类似于:找到平均值相等(差距不大)的项目,接着找这个人对这些项目的评分,然后用这些项目的评分来估计位置的评分。

二. 代码复现

        这个部分是这个算法的实现部分,我的建议是必须要搞明白M-distance 的推荐系统的思维过程才能看得懂代码,否则是肯定不行,而且由于这里面变量非常多,一个不小心就不知道这个变量代表的是哪一个数值参数了,所以两点建议①直到M-distance 的推荐系统的思维过程,需要什么参数(平均数,阈值...)②代码的话还是模拟计算机用脑子自己过一遍,这样理解起来更快,变量多了之后可以先记录看这个变量是怎么样使用的,再结合变量的名称就可以知道这个变量代表的含义了

        1. 数据导入

        导入数据的路径在D盘data文件夹movielens-943u1682m.txt文件

            MBR tempRecommender = new MBR("D:/data/movielens-943u1682m.txt",
                    943, 1682, 100000);

        2. 代码的初始化

        违约的设定值DEFAULT_RATING;传入的评分人的总数numUsers;项目总数numItems;输入数据的总条数(100000)numRatings;预测的结果predictions;compressedRatingMatrix矩阵用于存放输入的100000条数据,第一列存放评分人,第二列存放项目,第三列存放这个人对这个项目的评分;userDegrees存放这个人对多少个项目评分;userAverageRatings存放每个人的项目的平均打分;itemDegrees存放每个项目被多少人评过分;itemAverageRatings存放每个项目的平均分;userStartingIndices存放每个人评分开始对应的编号(0号人从0开始(默认值),比如0号人评了5个项目,那么1号人就是从第5号开始,userStartingIndices[1]=5);numNonNeighbors存储违约值;radius存放距离的阈值。


    /**
     * Default rating for 1-5 points.
     */
    public static final double DEFAULT_RATING = 3.0;

    /**
     * The total number of users.
     */
    private int numUsers;

    /**
     * The total number of items.
     */
    private int numItems;

    /**
     * The total number of ratings (non-zero values)
     */
    private int numRatings;

    /**
     * The predictions.
     */
    private double[] predictions;

    /**
     * Compressed rating matrix. User-item-rating triples.
     */
    private int[][] compressedRatingMatrix;

    /**
     * The degree of users (how many item he has rated).
     */
    private int[] userDegrees;

    /**
     * The average rating of the current user.
     */
    private double[] userAverageRatings;

    /**
     * The degree of users (how many item he has rated).
     */
    private int[] itemDegrees;

    /**
     * The average rating of the current item.
     */
    private double[] itemAverageRatings;

    /**
     * The first user start from 0. Let the first user has x ratings, the second
     * user will start from x.
     */
    private int[] userStartingIndices;

    /**
     * Number of non-neighbor objects.
     */
    private int numNonNeighbors;

    /**
     * The radius (delta) for determining the neighborhood.
     */
    private double radius;

        3. 核心代码

        3.1 基础数据的构建

        传入文件的路径,文件的总条数paraNumRatings,有多少人paraNumUsers,有多少项目paraNumItems。

        tempString用于记录文件的每一行的数据,将这每一行的数据按“,”分割,存放在compressedRatingMatrix的每一列。userDegrees记录每个人对多少项目数评分,itemDegrees记录每个项目被多少人评分,userStartingIndices记录每个人开始的编号,tempUserTotalScore记录每个人的评分的总和,tempItemTotalScore记录每个项目的总分,userAverageRatings记录每个人的平均分,itemAverageRatings记录每个项目的平均分。

    public MBR(String paraFilename, int paraNumUsers, int paraNumItems, int paraNumRatings) throws Exception {
        // Step 1. Initialize these arrays
        numItems = paraNumItems;
        numUsers = paraNumUsers;
        numRatings = paraNumRatings;

        userDegrees = new int[numUsers];
        userStartingIndices = new int[numUsers + 1];
        userAverageRatings = new double[numUsers];
        itemDegrees = new int[numItems];
        compressedRatingMatrix = new int[numRatings][3];
        itemAverageRatings = new double[numItems];

        predictions = new double[numRatings];

        System.out.println("Reading " + paraFilename);

        // Step 2. Read the data file.
        File tempFile = new File(paraFilename);
        if (!tempFile.exists()) {
            System.out.println("File " + paraFilename + " does not exists.");
            System.exit(0);
        } // Of if
        BufferedReader tempBufReader = new BufferedReader(new FileReader(tempFile));
        String tempString;
        String[] tempStrArray;
        int tempIndex = 0;
        userStartingIndices[0] = 0;
        userStartingIndices[numUsers] = numRatings;
        while ((tempString = tempBufReader.readLine()) != null) {
            // Each line has three values
            tempStrArray = tempString.split(",");
            compressedRatingMatrix[tempIndex][0] = Integer.parseInt(tempStrArray[0]);
            compressedRatingMatrix[tempIndex][1] = Integer.parseInt(tempStrArray[1]);
            compressedRatingMatrix[tempIndex][2] = Integer.parseInt(tempStrArray[2]);

            userDegrees[compressedRatingMatrix[tempIndex][0]]++;
            itemDegrees[compressedRatingMatrix[tempIndex][1]]++;

            if (tempIndex > 0) {
                // Starting to read the data of a new user.
                if (compressedRatingMatrix[tempIndex][0] != compressedRatingMatrix[tempIndex - 1][0]) {
                    userStartingIndices[compressedRatingMatrix[tempIndex][0]] = tempIndex;
                } // Of if
            } // Of if
            tempIndex++;
        } // Of while
        tempBufReader.close();

        double[] tempUserTotalScore = new double[numUsers];
        double[] tempItemTotalScore = new double[numItems];
        for (int i = 0; i < numRatings; i++) {
            tempUserTotalScore[compressedRatingMatrix[i][0]] += compressedRatingMatrix[i][2];
            tempItemTotalScore[compressedRatingMatrix[i][1]] += compressedRatingMatrix[i][2];
        } // Of for i

        for (int i = 0; i < numUsers; i++) {
            userAverageRatings[i] = tempUserTotalScore[i] / userDegrees[i];
        } // Of for i
        for (int i = 0; i < numItems; i++) {
            itemAverageRatings[i] = tempItemTotalScore[i] / itemDegrees[i];
        } // Of for i
    }// Of the first constructor

        3.2 leave-out-leave测试

        tempItemAverageRating记录除去某一个位置的数据之后的项目平均值q,如果这个被挖去的位置的这一行的项目平局值小于q\pm阈值,则记录这个项目对应的列,并且将这个位置的评分值加到tempTotal,邻居数自加1,如果被挖去的这个位置的邻居数大于0,则用tempTotal除以邻居数得到这个位置的评分——基于项目的评分

   /**
     *************************
     * Leave-one-out prediction. The predicted values are stored in predictions.
     *
     * @see predictions
     *************************
     */
    public void leaveOneOutPrediction() {
        double tempItemAverageRating;
        // Make each line of the code shorter.
        int tempUser, tempItem, tempRating;
        System.out.println("\r\nLeaveOneOutPrediction for radius " + radius);

        numNonNeighbors = 0;
        for (int i = 0; i < numRatings; i++) {
            tempUser = compressedRatingMatrix[i][0];
            tempItem = compressedRatingMatrix[i][1];
            tempRating = compressedRatingMatrix[i][2];

            // Step 1. Recompute average rating of the current item.
            tempItemAverageRating = (itemAverageRatings[tempItem] * itemDegrees[tempItem] - tempRating)
                    / (itemDegrees[tempItem] - 1);

            // Step 2. Recompute neighbors, at the same time obtain the ratings
            // Of neighbors.
            int tempNeighbors = 0;
            double tempTotal = 0;
            int tempComparedItem;
            for (int j = userStartingIndices[tempUser]; j < userStartingIndices[tempUser + 1]; j++) {
                tempComparedItem = compressedRatingMatrix[j][1];
                if (tempItem == tempComparedItem) {
                    continue;// Ignore itself.
                } // Of if

                if (Math.abs(tempItemAverageRating - itemAverageRatings[tempComparedItem]) < radius) {
                    tempTotal += compressedRatingMatrix[j][2];
                    tempNeighbors++;
                } // Of if
            } // Of for j

            // Step 3. Predict as the average value of neighbors.
            if (tempNeighbors > 0) {
                predictions[i] = tempTotal / tempNeighbors;
            } else {
                predictions[i] = DEFAULT_RATING;
                numNonNeighbors++;
            } // Of if
        } // Of for i
    }// Of leaveOneOutPrediction

        3.3 误差计算

        MAE:预测值-真实值的绝对值除以所有的数据数(100000)

    /**
     *************************
     * Compute the MAE based on the deviation of each leave-one-out.
     *
     * @author Fan Min
     *************************
     */
    public double computeMAE() throws Exception {
        double tempTotalError = 0;
        for (int i = 0; i < predictions.length; i++) {
            tempTotalError += Math.abs(predictions[i] - compressedRatingMatrix[i][2]);
        } // Of for i

        return tempTotalError / predictions.length;
    }// Of computeMAE

        RSME:预测值-真实值的绝对值的平方除以所有数据数(100000)

   /**
     *************************
     * Compute the MAE based on the deviation of each leave-one-out.
     *
     * @author Fan Min
     *************************
     */
    public double computeRSME() throws Exception {
        double tempTotalError = 0;
        for (int i = 0; i < predictions.length; i++) {
            tempTotalError += (predictions[i] - compressedRatingMatrix[i][2])
                    * (predictions[i] - compressedRatingMatrix[i][2]);
        } // Of for i

        double tempAverage = tempTotalError / predictions.length;

        return Math.sqrt(tempAverage);
    }// Of computeRSME

Day_55基于 M-distance 的推荐 (续)

一. 解法思路

        第54天实现的是item-based recommendation,即基于项目的推荐,今天我们要实现的基于 user-based recommendation即基于用户的推荐,其实本质上的计算方法并没有改变,只是将矩阵转置即可。

        这里我写了一个函数,用于转置压缩矩阵,再将它存储为一个文件,最后再将这个文件读入,像第54天解决问题的方法一样即可。

package Day_55;

/**
 * Recommendation with M-distance.
 * @author Fan Min minfanphd@163.com.
 */

import java.io.*;

public class MBR1 {



    /**
     * Compressed rating matrix. User-item-rating triples.
     */
    private int[][] compressedRatingMatrix;

    public MBR1(String paraFilename, int paraNumUsers, int paraNumItems,
                         int paraNumRatings)throws Exception {


        int user,item,score;
        String tempString;
        String[] tempStrArray;
        compressedRatingMatrix=new int [paraNumRatings][3];
        int[][] matrix=new int [paraNumUsers][paraNumItems];


        File tempFile = new File(paraFilename);
        if (!tempFile.exists()) {
            System.out.println("File " + paraFilename + " does not exists.");
            System.exit(0);
        } // Of if
        BufferedReader tempBufReader = new BufferedReader(new FileReader(tempFile));


        while ((tempString = tempBufReader.readLine()) != null) {
            tempStrArray = tempString.split(",");
            user = Integer.parseInt(tempStrArray[0]);
            item = Integer.parseInt(tempStrArray[1]);
            score = Integer.parseInt(tempStrArray[2]);
            matrix[user][item]=score;
        }

        int k=0;
        for (int i = 0; i <paraNumItems ; i++) {
            for (int j = 0; j < paraNumUsers; j++) {
                if(matrix[j][i]!=0){
                    compressedRatingMatrix[k][2]=matrix[j][i];
                    compressedRatingMatrix[k][0]=i;
                    compressedRatingMatrix[k][1]=j;
                    k++;
                }
            }
        }


        PrintStream ps = new PrintStream("D:/data/ceshi.txt");
        System.setOut(ps);
        for(int i=0;i<paraNumRatings;i++){
            System.out.println(compressedRatingMatrix[i][0]+","+compressedRatingMatrix[i][1]+
                    ","+compressedRatingMatrix[i][2]);
        }
        ps.close();
    }

    /**
     *************************
     * The entrance of the program.
     *
     * @param args
     *            Not used now.
     *************************
     */
    public static void main(String[] args) {
        try {
            MBR1 tempRecommender = new MBR1("D:/data/movielens-943u1682m.txt", 943, 1682, 100000);

        } catch (Exception ee) {
            System.out.println(ee);
        } // Of try
    }// Of main
}// Of class MBR

二. 运行结果

 

三. 补充54天的代码:

package Day_55;

/**
 * Recommendation with M-distance.
 * @author Fan Min minfanphd@163.com.
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class MBR {

    /**
     * Default rating for 1-5 points.
     */
    public static final double DEFAULT_RATING = 3.0;

    /**
     * The total number of users.
     */
    private int numUsers;

    /**
     * The total number of items.
     */
    private int numItems;

    /**
     * The total number of ratings (non-zero values)
     */
    private int numRatings;

    /**
     * The predictions.
     */
    private double[] predictions;

    /**
     * Compressed rating matrix. User-item-rating triples.
     */
    private int[][] compressedRatingMatrix;

    /**
     * The degree of users (how many item he has rated).
     */
    private int[] userDegrees;

    /**
     * The average rating of the current user.
     */
    private double[] userAverageRatings;

    /**
     * The degree of users (how many item he has rated).
     */
    private int[] itemDegrees;

    /**
     * The average rating of the current item.
     */
    private double[] itemAverageRatings;

    /**
     * The first user start from 0. Let the first user has x ratings, the second
     * user will start from x.
     */
    private int[] userStartingIndices;

    /**
     * Number of non-neighbor objects.
     */
    private int numNonNeighbors;

    /**
     * The radius (delta) for determining the neighborhood.
     */
    private double radius;

    /**
     *************************
     * Construct the rating matrix.
     *
     * @param paraRatingFilename
     *            the rating filename.
     * @param paraNumUsers
     *            number of users
     * @param paraNumItems
     *            number of items
     * @param paraNumRatings
     *            number of ratings
     *************************
     */
    public MBR(String paraFilename, int paraNumUsers, int paraNumItems, int paraNumRatings) throws Exception {
        // Step 1. Initialize these arrays
        numItems = paraNumItems;
        numUsers = paraNumUsers;
        numRatings = paraNumRatings;

        userDegrees = new int[numUsers];
        userStartingIndices = new int[numUsers + 1];
        userAverageRatings = new double[numUsers];
        itemDegrees = new int[numItems];
        compressedRatingMatrix = new int[numRatings][3];
        itemAverageRatings = new double[numItems];

        predictions = new double[numRatings];

        System.out.println("Reading " + paraFilename);

        // Step 2. Read the data file.
        File tempFile = new File(paraFilename);
        if (!tempFile.exists()) {
            System.out.println("File " + paraFilename + " does not exists.");
            System.exit(0);
        } // Of if
        BufferedReader tempBufReader = new BufferedReader(new FileReader(tempFile));
        String tempString;
        String[] tempStrArray;
        int tempIndex = 0;
        userStartingIndices[0] = 0;
        userStartingIndices[numUsers] = numRatings;
        while ((tempString = tempBufReader.readLine()) != null) {
            // Each line has three values
            tempStrArray = tempString.split(",");
            compressedRatingMatrix[tempIndex][0] = Integer.parseInt(tempStrArray[0]);
            compressedRatingMatrix[tempIndex][1] = Integer.parseInt(tempStrArray[1]);
            compressedRatingMatrix[tempIndex][2] = Integer.parseInt(tempStrArray[2]);

            userDegrees[compressedRatingMatrix[tempIndex][0]]++;
            itemDegrees[compressedRatingMatrix[tempIndex][1]]++;

            if (tempIndex > 0) {
                // Starting to read the data of a new user.
                if (compressedRatingMatrix[tempIndex][0] != compressedRatingMatrix[tempIndex - 1][0]) {
                    userStartingIndices[compressedRatingMatrix[tempIndex][0]] = tempIndex;
                } // Of if
            } // Of if
            tempIndex++;
        } // Of while
        tempBufReader.close();

        double[] tempUserTotalScore = new double[numUsers];
        double[] tempItemTotalScore = new double[numItems];
        for (int i = 0; i < numRatings; i++) {
            tempUserTotalScore[compressedRatingMatrix[i][0]] += compressedRatingMatrix[i][2];
            tempItemTotalScore[compressedRatingMatrix[i][1]] += compressedRatingMatrix[i][2];
        } // Of for i

        for (int i = 0; i < numUsers; i++) {
            userAverageRatings[i] = tempUserTotalScore[i] / userDegrees[i];
        } // Of for i
        for (int i = 0; i < numItems; i++) {
            itemAverageRatings[i] = tempItemTotalScore[i] / itemDegrees[i];
        } // Of for i
    }// Of the first constructor

    /**
     *************************
     * Set the radius (delta).
     *
     * @param paraRadius
     *            The given radius.
     *************************
     */
    public void setRadius(double paraRadius) {
        if (paraRadius > 0) {
            radius = paraRadius;
        } else {
            radius = 0.1;
        } // Of if
    }// Of setRadius

    /**
     *************************
     * Leave-one-out prediction. The predicted values are stored in predictions.
     *
     * @see predictions
     *************************
     */
    public void leaveOneOutPrediction() {
        double tempItemAverageRating;
        // Make each line of the code shorter.
        int tempUser, tempItem, tempRating;
        System.out.println("\r\nLeaveOneOutPrediction for radius " + radius);

        numNonNeighbors = 0;
        for (int i = 0; i < numRatings; i++) {
            tempUser = compressedRatingMatrix[i][0];
            tempItem = compressedRatingMatrix[i][1];
            tempRating = compressedRatingMatrix[i][2];

            // Step 1. Recompute average rating of the current item.
            tempItemAverageRating = (itemAverageRatings[tempItem] * itemDegrees[tempItem] - tempRating)
                    / (itemDegrees[tempItem] - 1);

            // Step 2. Recompute neighbors, at the same time obtain the ratings
            // Of neighbors.
            int tempNeighbors = 0;
            double tempTotal = 0;
            int tempComparedItem;
            for (int j = userStartingIndices[tempUser]; j < userStartingIndices[tempUser + 1]; j++) {
                tempComparedItem = compressedRatingMatrix[j][1];
                if (tempItem == tempComparedItem) {
                    continue;// Ignore itself.
                } // Of if

                if (Math.abs(tempItemAverageRating - itemAverageRatings[tempComparedItem]) < radius) {
                    tempTotal += compressedRatingMatrix[j][2];
                    tempNeighbors++;
                } // Of if
            } // Of for j

            // Step 3. Predict as the average value of neighbors.
            if (tempNeighbors > 0) {
                predictions[i] = tempTotal / tempNeighbors;
            } else {
                predictions[i] = DEFAULT_RATING;
                numNonNeighbors++;
            } // Of if
        } // Of for i
    }// Of leaveOneOutPrediction

    /**
     *************************
     * Compute the MAE based on the deviation of each leave-one-out.
     *
     * @author Fan Min
     *************************
     */
    public double computeMAE() throws Exception {
        double tempTotalError = 0;
        for (int i = 0; i < predictions.length; i++) {
            tempTotalError += Math.abs(predictions[i] - compressedRatingMatrix[i][2]);
        } // Of for i

        return tempTotalError / predictions.length;
    }// Of computeMAE

    /**
     *************************
     * Compute the MAE based on the deviation of each leave-one-out.
     *
     * @author Fan Min
     *************************
     */
    public double computeRSME() throws Exception {
        double tempTotalError = 0;
        for (int i = 0; i < predictions.length; i++) {
            tempTotalError += (predictions[i] - compressedRatingMatrix[i][2])
                    * (predictions[i] - compressedRatingMatrix[i][2]);
        } // Of for i

        double tempAverage = tempTotalError / predictions.length;

        return Math.sqrt(tempAverage);
    }// Of computeRSME

    /**
     *************************
     * The entrance of the program.
     *
     * @param args
     *            Not used now.
     *************************
     */
    public static void main(String[] args) {
        try {
            MBR tempRecommender = new MBR("D:/data/ceshi.txt",1682,
                    943,  100000);

            for (double tempRadius = 0.2; tempRadius < 0.6; tempRadius += 0.1) {
                tempRecommender.setRadius(tempRadius);

                tempRecommender.leaveOneOutPrediction();
                double tempMAE = tempRecommender.computeMAE();
                double tempRSME = tempRecommender.computeRSME();

                System.out.println("Radius = " + tempRadius + ", MAE = " + tempMAE + ", RSME = " + tempRSME
                        + ", numNonNeighbors = " + tempRecommender.numNonNeighbors);
            } // Of for tempRadius
        } catch (Exception ee) {
            System.out.println(ee);
        } // Of try
    }// Of main
}// Of class MBR

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/674396.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

对象的构造顺序

问题 C 中的类可以定义多个对象&#xff0c;那个对象构造的顺序是怎样的&#xff1f; 对于局部对象 当程序执行流到达对象的定义语句时进行构造 下面程序中的对象构造顺序是什么&#xff1f; 对于堆对象 当程序执行流到达 new 语句时创建对象 使用 new 创建对象将自动触发构…

python 使用 openpyxl 处理 Excel 教程

目录 前言一、安装openpyxl库二、新建excel及写入单元格1.创建一个xlsx格式的excel文件并保存2.保存成流(stream)3.写入单元格 三、创建sheet工作表及操作四、读取excel和单元格1.读取 excel 文件2.读取单元格3.获取某一行某一列的数据4.遍历所有单元格5.遍历指定行列范围的单元…

Android卡顿优化

卡顿的定义 如果在一个Vsync周期内&#xff08;60HZ的屏幕上就是16.6ms&#xff09;&#xff0c;按照整个上帧显示的执行的顺序来看&#xff0c;应用UI线程的绘制、RenderThread线程的渲染、SurfaceFlinger/HWC的图层合成以及最终屏幕上的显示这些动作没有全部都执行完成的话&…

【C语言】-- X型图案

今天刷了牛客网上的一道题&#xff0c;不难&#xff0c;但思路很重要&#xff0c;否则你就得写一长串代码&#xff0c;下面是要求。牛客网链接->X形图案。 下面是两组示例。 通过观察示例&#xff0c;我们发现输入的数字是奇数时&#xff0c;图案最中间只有一个*&#xff0c…

什么是Ajax?Ajax如何发送请求(详)

本篇来讲关于Ajax的内容&#xff0c;当然还有小伙伴可能不知道该怎么读 "Ajax"&#xff0c;它读 "阿贾克斯" &#xff0c;当然了读法可能因人而异&#xff0c;下面来进入正题&#xff0c;先来了解一下什么是Ajax&#xff1f; Ajax 是什么&#xff1f; Ajax…

魔法与现实-如何使用GPT帮我改一个万行vue代码中的BUG

开篇 传说在人类诞生之初是和魔法共存的。随时时间的流失,人们逐步开始淡忘了魔法。也有传说魔法是亚瑟王于“剑栏“一战(Battle of Camlann)后梅林永远封存了魔法使其不被心术不正者所使用。不管哪种说法,随着时间的流失,人类在飞速进步。从水利磨坊到蒸汽机的发明、再到…

Latex中表格Table环境和Tabular环境

目录 一、Table和Tabular的区别 二、一个简单的Table环境示例&#xff1a; 三、Latex的“自动换行”功能 四、Latex多行和多列 五、使用tablesgenerator快速将excel表格转换成tex代码 六、设置表格的宽度与页面宽度一致 说明:一至四内容来自Latex中使用Table&#xff08;表…

Scala入门【运算符和流程控制】

运算符 在 Scala 中其实是没有运算符的&#xff0c;所有运算符都是方法。我们只是省去了 .方法名() 中的点 . 和括号 () 。 调用对象的方法时&#xff0c;点 . 可以省略&#xff1b;如果函数参数只有一个&#xff0c;或者没有参数&#xff0c;括号()可以省略。 //num1 n…

Unity解决:GIS(GPS的经纬度坐标)定位系统坐标转unity坐标(世界坐标)

目录 一、前言 二、功能实现 三、测试 四、备注 如果要实现该效果的demo&#xff0c;请联系作者 一、前言 最近项目中用到了第三方的定位系统&#xff0c;有的是使用GPS定位、有的是使用UWB定位。第三方的定位系统把他们的定位信息通过网络发送给Unity&#xff0c;在Unity…

项目集活动—项目集定义阶段活动

项目集活动是为支持项目集而开展的任务和工作&#xff0c;贯穿整个项目集生命周期。 项目集活动包括&#xff1a; 项目集定义阶段活动 项目集交付阶段活动项目集收尾阶段活动 鉴于项目集的范围和复杂性&#xff0c;在整个项目集生命周期中&#xff0c;将执行许多项目集支持活…

走向CV的通用人工智能:从GPT和大型语言模型中汲取的经验教训 (上)

点击蓝字 关注我们 关注并星标 从此不迷路 计算机视觉研究院 公众号ID&#xff5c;计算机视觉研究院 学习群&#xff5c;扫码在主页获取加入方式 论文地址&#xff1a;https://arxiv.org/pdf/2306.08641.pdf 计算机视觉研究院专栏 Column of Computer Vision Institute 人工智能…

交织技术详解

本专栏包含信息论与编码的核心知识&#xff0c;按知识点组织&#xff0c;可作为教学或学习的参考。markdown版本已归档至【Github仓库&#xff1a;https://github.com/timerring/information-theory 】或者公众号【AIShareLab】回复 信息论 获取。 文章目录 交织技术1.突发错误…

Linux系统:ulimit命令

目录 一、理论 1.ulimit命令 二、实验 1.打开的最大文件描述符的数量为65535 一、理论 1.ulimit命令 &#xff08;1&#xff09;概念 ulimit是一个计算机命令&#xff0c;用于shell启动进程所占用的资源&#xff0c;可用于修改系统资源限制&#xff0c;限制每个用户可使用…

资源有限的大型语言模型的全参数微调

文章目录 摘要1、简介2、相关工作3、方法3.1、重新思考optimizer的功能3.1.1、使用SGD3.1.2、隐式BatchSize 3.2、LOMO:低内存优化3.3、使用LOMO稳定训练3.3.1、梯度归一化和裁剪的替代方法3.3.2、缓解精度下降 4、实验4.1、内存配置4.2、吞吐量4.3、下游性能4.3.1、主要结果4.…

复杂的HANASQL 多行并入一行

点击蓝字 关注我们 一 前言 基于HANA的内存数据库的强大性能, SAP建议把业务逻辑下沉到HANA中计算.以便减去应用服务器的负担,让程序性能更好一些. SAP本身的一些复杂的业务逻辑比如MRP运算(MD01)也有了新的事务 MD01N (MRP LIVE) 报表类的数据分析程序尤其适用. 动态报表强化了…

PromptBench:大型语言模型的对抗性基准测试

PromptBench是微软研究人员设计的一个用于测量大型语言模型(llm)对对抗性提示鲁棒性的基准测试。这个的工具是理解LLM的重要一步&#xff0c;随着这些模型在各种应用中越来越普遍&#xff0c;这个主题也变得越来越重要。 研究及其方法论 PromptBench采用多种对抗性文本攻击&am…

阿里云服务器的存储容量和性能如何?是否支持多种存储类型?

阿里云服务器的存储容量和性能如何&#xff1f;是否支持多种存储类型&#xff1f;   本文由阿里云代理商[聚搜云]撰写   阿里云服务器作为业界领先的云计算服务提供商&#xff0c;其存储容量和性能一直受到广泛关注。本文将为您介绍阿里云服务器的存储容量、性能以及支持的…

《斯坦福数据挖掘教程·第三版》读书笔记(英文版)Chapter 12 Large-Scale Machine Learning

来源&#xff1a;《斯坦福数据挖掘教程第三版》对应的公开英文书和PPT Chapter 12 Large-Scale Machine Learning Algorithms called “machine learning” not only summarize our data; they are perceived as learning a model or classifier from the data, and thus dis…

Spring Boot 如何使用 @RequestParam 进行数据校验

Spring Boot 如何使用 RequestParam 进行数据校验 在 Web 应用程序中&#xff0c;用户提交的数据通常以请求参数的形式传递。在 Spring Boot 中&#xff0c;可以使用 RequestParam 注解来获取请求参数。但是&#xff0c;如何确保这些请求参数的有效性呢&#xff1f;在本文中&a…

Webots介绍

Webots介绍 1 介绍1.1 概述1.2 应用1.3 入门要求1.4 技术支持1.5 仿真步骤世界&#xff08;webots定义&#xff09;控制器超级控制器 1.6 平台能力三维建模能力物理引擎外设支持 2 软件使用启动webots用户界面文件菜单编辑菜单查看菜单模拟菜单构建菜单叠加菜单工具菜单帮助菜单…