Mixed food recommendation method, electronic equipment and storage medium
By obtaining user diet records and optimizing evolutionary algorithms, personalized food recommendations are generated, and the problem of difficulty in taking into account both dietary preferences and nutritional needs in the existing technology is solved, and an efficient food recommendation solution is achieved.
Patent Information
- Application Number
- CN202411481791.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2024-11-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art is difficult to take into account the user's dietary preferences, dietary diversity and nutritional elements needs at the same time, and it is difficult for traditional food recommendation methods to generate personalized dietary plans.
By obtaining the user's dietary record data, identify user groups that are similar to the target user's dietary habits, generate pre-recommended food combinations, and use evolutionary algorithms to optimize the nutritional components of the food combinations, adjust the amount of food to achieve nutritional balance.
It provides personalized and comprehensive food recommendations to meet users' dietary preferences and nutritional needs, and improves the accuracy and user experience of recommendations.
Smart Images

Figure CN119046534A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of food recommendation, and in particular to a mixed food recommendation method, electronic device and storage medium. Background Art
[0002] As people's living standards improve, their concept of diet is also gradually changing. Healthy food combinations and balanced nutrition intake have been widely valued by people. However, due to the lack of knowledge about the nutrients contained in various foods and long-term eating habits, it is difficult for people to make reasonable dietary arrangements.
[0003] In the related art, food is usually matched by a professional nutritionist, but this method is limited by the experience and professionalism of the nutritionist himself, and the resulting mixed food may not meet the needs of the user. Summary of the invention
[0004] The present application is proposed in consideration of the above-mentioned problems. According to one aspect of the present application, a mixed food recommendation method is provided, including: obtaining user diet record data, the user diet record data including diet records of multiple users, the multiple users including a target user, and for each of the multiple users, the user's diet record including the food consumed by the user; based on the user diet record data, determining a first preset number of users among the multiple users whose eating habits are similar to those of the target user; generating a pre-recommended food combination based on at least the diet records corresponding to each of the first preset number of users, the pre-recommended food combination including a second preset number of foods; based on the pre-recommended food combination, initializing a population, wherein the population includes a third preset number of individuals, and the third preset number of individuals. Each of the individuals corresponds to a different consumption amount combination, and the consumption amount combination includes consumption amounts corresponding to a second preset number of foods; based on the objective function value of each individual in the population, the population is iteratively optimized, wherein the objective function is the difference between the nutrient content of the corresponding individual and the standard nutrient content, the nutrients include a variety of nutrients, and the standard nutrient content includes standard contents corresponding to the multiple nutrients; when the number of iterative optimizations reaches an iteration number threshold, a recommended recipe for the target user is generated based on the individual with the smallest objective function value in the current population; wherein the recommended recipe includes a pre-recommended food combination and the consumption amount combination corresponding to the individual with the smallest objective function value.
[0005] Exemplarily, based on user diet record data, determining a first preset number of users among multiple users whose eating habits are similar to those of a target user includes: determining, based on the user diet record data, a score for each food in a food set given by each user among the multiple users, where the food set includes foods eaten by each user among the multiple users; determining the similarity between each user among the multiple users except the target user and the target user based on the score for each food in the food set given by each user among the multiple users; determining a first preset number of users among the multiple users whose eating habits are similar to those of the target user based on the similarity between each user among the multiple users except the target user and the target user.
[0006] Exemplarily, for each user among multiple users, the user's diet record also includes the user's total consumption frequency and the consumption frequency of each food consumed by the user; based on the user's diet record data, determining the score of each food in the food set by each user among the multiple users, including: for each user among the multiple users, using a first score determination operation to determine the user's score for the food in the food set that the user has consumed; using a second score determination operation to determine the user's score for the food in the food set that the user has not consumed; wherein the first score determination operation includes: for each food consumed by the user, determining the user's score for the food based on the ratio of the user's consumption frequency for the food to the user's total consumption frequency; the second score determination operation includes: for each food that the user has not consumed, using a collaborative filtering recommendation algorithm to determine the user's score for the food.
[0007] Exemplarily, generating a pre-recommended food combination based on at least the dietary records corresponding to a first preset number of users includes: determining, based on the user dietary record data, the scores of each food in a food set by a first preset number of users, the food set including foods eaten by each of a plurality of users; calculating the average of the scores of each food in the food set by the first preset number of users to obtain an average score for each food in the food set; determining a second preset number of foods in the food set with higher average scores to generate a pre-recommended food combination; or, determining, based on the user dietary record data, the scores of each food in a food set by a target user and a first preset number of users, the food set including foods eaten by each of a plurality of users; calculating the average of the scores of each food in the food set by the target user and the first preset number of users to obtain an average score for each food in the food set; determining a second preset number of foods in the food set with higher average scores to generate a pre-recommended food combination. or, for the target user and each of the first preset number of users, based on the user's dietary record in the user dietary record data, determine the score of each of the foods consumed by the user; for the foods consumed by the target user and each of the first preset number of users, select a second preset number of foods with higher food scores to generate a pre-recommended food combination; or, for each of the first preset number of users, based on the user's dietary record in the user dietary record data, determine the score of each of the foods consumed by the user, wherein the user's dietary record also includes the user's total consumption frequency and the consumption frequency of each food consumed by the user; for the foods consumed by each of the first preset number of users, select a second preset number of foods with higher food scores to generate a pre-recommended food combination.
[0008] Exemplarily, based on the objective function value of each individual in the population, the population is iteratively optimized, including: in each iteration of the iterative optimization process, each individual in the population is used as a target individual, and the following individual optimization operations are performed: determining the neighborhood of the target individual in the population; optimizing through crossover operations and polynomial mutation operations in sequence based on the target individual and the individuals included in the neighborhood of the target individual to obtain a new individual; comparing the objective function value of the new individual with that of the target individual; when the objective function value of the target individual is less than or equal to that of the new individual, maintaining the target individual unchanged; when the objective function value of the target individual is greater than that of the new individual, updating the new individual to the target individual.
[0009] Exemplarily, before comparing the objective function values of the new individual with those of the target individual, the individual optimization operation also includes: for each consumption amount in the new individual, determining whether the consumption amount is within a preset consumption amount range; when the consumption amount is greater than the upper limit of the preset consumption amount range, adjusting the consumption amount to the upper limit of the preset consumption amount range; when the consumption amount is less than the lower limit of the preset consumption amount range, adjusting the consumption amount to the lower limit of the preset consumption amount range.
[0010] Exemplarily, the method also includes: in each iteration of iterative optimization, for the first fourth preset number of individual optimization operations performed in the current iteration, after each individual optimization operation is completed, performing the following neighbor update operation: randomly selecting an individual in the neighborhood of the current target individual as a neighbor individual, the current target individual being the target individual corresponding to the current individual optimization operation; comparing the objective function value of the neighbor individual with that of the current target individual; when the objective function value of the current target individual is less than that of the neighbor individual, using the current target individual to update the neighbor individual; wherein the updated neighbor individual is the same as the current target individual.
[0011] Exemplarily, after the new individual is updated as the target individual, the individual optimization operation also includes: comparing the content of each nutrient element in the nutrient content of the target individual with the standard content of the corresponding nutrient element to determine an overnutrition set and an undernutrition set, the overnutrition set including nutrient elements with greater than the standard content among the multiple nutrient elements corresponding to the target individual, and the undernutrition set including nutrient elements with less than the standard content among the multiple nutrient elements corresponding to the target individual; randomly selecting a nutrient element from the overnutrition set, and reducing the consumption of a food corresponding to the nutrient element in the target individual based on a first preset step value; randomly selecting a nutrient element from the undernutrition set, and increasing the consumption of a food corresponding to the nutrient element in the target individual based on a second preset step value; comparing the objective function value of the individual obtained after adjustment with the objective function value of the target individual; when the objective function value of the individual obtained after adjustment is less than that of the target individual, updating the individual obtained after adjustment as the target individual.
[0012] According to another aspect of the present application, an electronic device is provided, including a processor and a memory, wherein a computer program is stored in the memory, and the processor is used to execute the computer program to implement the above method.
[0013] According to another aspect of the present application, a computer-readable storage medium is provided, storing a computer program / instruction, and the computer program / instruction implements the above method when executed by a processor.
[0014] The above technical solution first determines a first preset number of users with similar dietary habits to the target user among multiple users, and then generates a pre-recommended food combination based on at least the dietary records corresponding to each of the first preset number of users, and then initializes the population based on the pre-recommended food combination, and optimizes the population based on the difference between the individual nutrient content and the standard nutrient content through iterative optimization, and finally generates a recommended recipe based on the best individual (i.e., the individual with the smallest objective function value in the population) obtained after the optimization. This solution considers the dietary records of multiple users similar to the target user to generate pre-recommended food combinations, which can take into account the dietary preferences and dietary diversity of the target user, and through iterative optimization, the consumption combination corresponding to the individuals in the population can be adjusted, and then the nutrient content corresponding to the individuals can be adjusted, so that the recommended recipe finally obtained can meet the target user's intake needs for various nutrients. In short, this solution can provide users with accurate and comprehensive recommended recipes, which can meet the user's dietary preferences, dietary diversity and nutritional needs, and help improve the user experience.
[0015] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] By describing the embodiments of the present application in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present application will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the accompanying drawings, the same reference numerals generally represent the same components or steps.
[0017] Figure 1 A schematic flow chart showing a mixed food recommendation method according to an embodiment of the present application; Figure 2 A schematic diagram showing the nutrition optimization process of a solution of an embodiment of the present application and multiple existing solutions; Figure 3 A schematic block diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the present application more obvious, the example embodiments according to the present application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application, and it should be understood that the present application is not limited to the example embodiments described herein. Based on the embodiments of the present application described in the present application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of protection of the present application.
[0019] As mentioned above, in the related art, dietitians usually perform dietary matching to obtain mixed foods (also referred to as recommended recipes), but due to the experience and professionalism of the nutritionists themselves, the obtained mixed foods may not meet the needs of users. For example, it may be difficult for nutritionists to take into account a variety of foods when matching diets, and the recommended recipes obtained by matching may be relatively simple. For another example, some of the foods in the recommended recipes obtained by nutritionists may not meet the user's dietary preferences. In some related technologies, a user's recommended recipe is generated by a food recommendation method such as a pre-trained neural network. This food recommendation method can intelligently screen out a suitable food list based on the user's specific characteristics, such as physical condition, taste preferences, nutritional deficiencies and other factors. However, as users put forward more requirements for food recommendations, traditional food recommendation technologies are difficult to take into account the needs of multiple food recommendations at the same time. In view of this, the present application provides a mixed food recommendation method, an electronic device and a storage medium, which can take into account the user's nutritional needs, dietary preferences and dietary diversity, help to improve the accuracy and comprehensiveness of food recommendations, and help to improve the user's experience. The method, electronic device and storage medium are described in detail below.
[0020] According to one aspect of an embodiment of the present application, a mixed food recommendation method is provided. Figure 1 FIG. 1 is a schematic flow chart of a mixed food recommendation method according to an embodiment of the present application. Figure 1 As shown, the method may include step S110, step S120, step S130, step S140, step S150 and step S160.
[0021] In step S110, user diet record data is obtained, the user diet record data includes diet records of multiple users, the multiple users include a target user, and for each user among the multiple users, the user's diet record includes food consumed by the user.
[0022] The user diet record data can be obtained by pre-collection. For example, the daily diet of multiple users (including the food consumed by the users each time) can be tracked and recorded over a period of time (e.g., one week, one month, one year, etc.), thereby obtaining the diet records of multiple users and further obtaining the user diet record data. In a specific embodiment, a health tracking application (e.g., MyFitnessPal) can be used to obtain the diet records of multiple users.
[0023] It is understandable that the specific number of users included in the user diet record data can be selected according to actual needs.
[0024] In step S120, based on the user's dietary record data, a first preset number of users whose dietary habits are similar to the target user are determined from among the multiple users. It is understood that the first preset number of users does not include the target user.
[0025] The first preset number can be set according to actual needs. For example, it can be determined according to the accuracy of the pre-recommended food combination and the demand for food diversity. It can be understood that the more the first preset number, the more data used to determine the pre-recommended food combination in the subsequent steps, which helps to generate the pre-recommended food combination more accurately, and because the data of more users are integrated, the food diversity of the generated pre-recommended food combination can be guaranteed. However, the increase in the first preset number will inevitably lead to an increase in the required computing resources and computing time. Therefore, the first preset number can be determined by comprehensively considering the accuracy of the pre-recommended food combination, the demand for food diversity and computing efficiency.
[0026] Optionally, step S120, based on the user's dietary record data, determines a first preset number of users whose dietary habits are similar to those of the target user among multiple users, which may specifically include the following steps: determining the overlap between the dietary record of each user except the target user (which may be referred to as other users) among the multiple users and the dietary record of the target user, and the overlap may be expressed by the number of foods included in the dietary record of any other user and the foods included in the dietary record of the target user. For example, the overlap number may be directly used as the overlap, or the ratio of the overlap number to the number of foods included in the dietary record of the target user may be used as the overlap. For example, if the dietary record of one of the other users and the dietary record of the target user both include oats and milk, the overlap number is 2, and in this embodiment, the overlap may be 2. The scheme of this optional embodiment determines the similarity of dietary habits by the overlap of foods consumed by different users, and can quickly and accurately determine the first preset number of users similar to the target user, thereby providing a more accurate basis for subsequent steps. In other embodiments, the first preset number of users may also be determined based on the rating of each user on the food. The scheme is described in detail below and will not be repeated here.
[0027] In step S130, a pre-recommended food combination is generated based on at least the dietary records corresponding to the first preset number of users, and the pre-recommended food combination includes a second preset number of foods.
[0028] It is understood that the second preset number of foods included in the pre-recommended food combination is a second preset number of foods that are different from each other. The second preset number can be selected according to the actual needs of the target user. In some embodiments, the second preset number can be in the range of [5, 15]. In a specific embodiment, the second preset number can be 8, that is, the pre-recommended food combination includes 8 different foods.
[0029] After obtaining the first preset number of users with similar eating habits to the target user, a pre-recommended food combination can be generated based on at least the diet records corresponding to each of the first preset number of users. In some embodiments, all foods consumed by the first preset number of users and the number of users among the first preset number of users who have consumed any one of the total foods can be counted. For example, if two of the first preset number of users have eaten oats, the number of users corresponding to oats is 2. Then, the foods are sorted from large to small according to the number of users corresponding to each of the total foods. Next, the first second preset number of foods that are ranked high are taken as the pre-recommended food combination. Of course, the pre-recommended food combination can also be generated based on at least the ratings of the first preset number of users on the foods, which will not be elaborated.
[0030] As mentioned above, it is difficult for traditional food recommendation technology to take into account the needs of multiple food recommendations at the same time. The inventor found through research that traditional food recommendation technology and the dietary combinations given by nutritionists are usually selected based on the personal preferences of the target user. However, this method will cause the food in the obtained recipe to be limited to the food that the target user likes or is familiar with, and unfamiliar foods are often ignored, which will lead to the monotony of the user's daily diet. In the scheme of this example, the dietary records corresponding to the first preset number of users with similar dietary habits to the user are used to generate pre-recommended food combinations. This method can generate pre-recommended food combinations within a larger range of foods, and because the dietary habits of the first preset number of users referenced are similar to those of the target user, it helps to make each food in the generated pre-recommended food combination meet the user's taste needs. In short, this method of generating pre-recommended food combinations can take into account the dietary preferences and dietary diversity of the target user, which helps to improve the user experience.
[0031] In step S140, a population is initialized based on the pre-recommended food combination, wherein the population includes a third preset number of individuals, each of the third preset number of individuals corresponds to a different consumption amount combination, and the consumption amount combination includes consumption amounts corresponding one-to-one to the second preset number of foods.
[0032] The third preset number can be determined as needed and will not be elaborated herein.
[0033] In this article, serving sizes are in grams (g) unless otherwise stated.
[0034] After obtaining the pre-recommended food combination, the population can be initialized according to the pre-recommended food combination. For example, the population can be initialized as pop = {x 1 ,x 2 …x n}, n is equal to the third preset number. Those skilled in the art can understand the specific method of initializing the population, which will not be described in detail.
[0035] It can be understood that in the scheme of this example, for each individual, the individual includes a gene position corresponding to a second preset number of foods, and each gene position is used to store the consumption of the corresponding food. In a specific embodiment, initializing the population may include the following steps: using an individual generation operation to generate a third preset number of individuals. Among them, the individual generation operation includes: for each gene position of each individual, an consumption amount can be randomly selected within a preset consumption amount range as the gene value of the gene position, that is, the consumption amount of the food corresponding to the gene position. Of course, other methods of initializing the population commonly used in evolutionary algorithms can also be used to initialize the population, which will not be repeated.
[0036] The preset consumption range can be determined according to the user's situation, for example, the preset consumption range can be [10g, 400g]. The random generation of gene values in the above scheme helps to ensure population diversity, and because each consumption included in each individual is within the preset consumption range, this helps to ensure the rationality of the generated individuals.
[0037] In step S150, the population is iteratively optimized based on the objective function value of each individual in the population, wherein the objective function is the difference between the nutrient content of the corresponding individual and the standard nutrient content, the nutrient content includes a variety of nutrient elements, and the standard nutrient content includes standard contents corresponding to the multiple nutrient elements one by one.
[0038] It is understood that each individual includes an intake amount corresponding to the second preset number of foods. Therefore, the nutritional content of the individual, that is, the content of multiple nutritional elements in the individual, can be determined based on the intake amount combination corresponding to the individual and the corresponding second preset number of foods.
[0039] In this example, the objective function is the difference between the nutrient content in the corresponding individual and the standard nutrient content, that is, for an individual, the objective function of the individual can be expressed as: , in, is the i-th individual; A is the relationship matrix of multiple nutrients corresponding to each food in this individual; S is the standard nutrient content.
[0040] Optionally, the types and quantities of the nutritional elements in the nutritional ingredients can be selected as needed. For example, the nutritional elements may include nine types, specifically including: calories, protein, fat, carbohydrates, vitamin A, vitamin B, calcium, iron, and vitamin C.
[0041] It is understood that the standard nutrient content is the recommended intake of nutrients, that is, the recommended intake of each nutrient element in a plurality of nutrients. The standard nutrient content can be determined based on experience or relevant data. For example, it can be determined by referring to the "Dietary Nutrient Reference Intake for Chinese Residents".
[0042] Optionally, the iterative optimization method can be implemented by using any one or several population evolution operations currently available or developed in the future. The population evolution operation includes but is not limited to selection operation, crossover operation, mutation operation, polynomial mutation operation, etc. Those skilled in the art can understand the specific implementation methods of various population evolution operations, which will not be described in detail.
[0043] In step S160, when the number of iterative optimization reaches the iteration number threshold, a recommended recipe for the target user is generated based on the individual with the smallest objective function value in the current population; wherein the recommended recipe includes a pre-recommended food combination and a consumption combination corresponding to the individual with the smallest objective function value.
[0044] In this example, the iteration number threshold can be selected according to actual needs. When the number of iterative optimization reaches the iteration number threshold, it can be considered that the population has evolved to a better level as a whole. At this time, the individual with the smallest objective function value in the current population can be selected to generate a recommended recipe for the target user. The individual with the smallest objective function value is the individual with the smallest difference in nutrient content from the standard in the current population.
[0045] It can be understood that the consumption amount combination corresponding to the individual includes the consumption amount corresponding to the second preset number of foods. The recommended recipe includes the second preset number of foods and the consumption amount corresponding to the second preset number of foods, and the consumption amount corresponding to the second preset number of foods contained in the recommended recipe is the same as the individual with the smallest objective function value in the current population. For example, the second preset number of foods includes food A, food B and food C, and the individual with the smallest objective function value in the current population is {10,20,30}. In this case, the recommended recipe is: 10g food A, 20g food B, 30g food C.
[0046] In the above technical solution, firstly, a first preset number of users with similar dietary habits to the target user are determined among multiple users, and then a pre-recommended food combination is generated based on at least the dietary records corresponding to each of the first preset number of users, and then the population is initialized based on the pre-recommended food combination, and the population is tuned based on the difference between the individual nutrient content and the standard nutrient content through iterative optimization, and finally a recommended recipe is generated based on the best individual (i.e., the individual with the smallest objective function value in the population) obtained after the tuning. This solution considers the dietary records of multiple users similar to the target user to generate pre-recommended food combinations, which can take into account the dietary preferences and dietary diversity of the target user, and through iterative optimization, the consumption combination corresponding to the individuals in the population can be adjusted, and then the nutrient content corresponding to the individuals can be adjusted, so that the recommended recipe finally obtained can meet the target user's intake needs for various nutrients. In short, this solution can provide users with accurate and comprehensive recommended recipes, which can meet the user's dietary preferences, dietary diversity and nutritional needs, and help improve the user experience.
[0047] Exemplarily, step S120, determining a first preset number of users among multiple users whose eating habits are similar to those of the target user based on the user's diet record data, may specifically include the following steps S121, S122, and S123.
[0048] In step S121 , based on the user diet record data, a score of each of the plurality of users on each food in a food set is determined, where the food set includes the food consumed by each of the plurality of users.
[0049] In step S122, based on the score given by each user among the multiple users to each food in the food set, the similarity between each user among the multiple users except the target user and the target user is determined.
[0050] In step S123, based on the similarity between each user except the target user among the multiple users and the target user, a first preset number of users among the multiple users whose eating habits are similar to the target user are determined.
[0051] In the scheme of this example, the score of each user for each food in the food set can be determined first. Optionally, for each user among multiple users, the user's diet record can also include the user's total consumption frequency and the consumption frequency of each food consumed by the user. Among them, the total consumption frequency can be used to represent the total frequency of the corresponding user's intake of food in a specific period (i.e., the specific survey period below), and the consumption frequency of each food consumed by the user in a specific period refers to the frequency of the user's intake of the food. For example, as described above, the diet record of each user can be determined based on the user's diet over a period of time. That is, the user's diet record data can be determined by collecting the diet of multiple users during a specific survey period. When the specific survey period is 300 days, based on the user's three meals a day, the user's total consumption frequency is 900, and the user's consumption frequency of a specific food is the number of times the specific food is consumed in these 900 diets.
[0052] It can be understood that since the food set includes the food consumed by each of the multiple users. Therefore, for a single user, the food set includes the food consumed by the user and the food that the user has not consumed. For the food consumed by the user, the score of the food can be determined based on the frequency of consumption of the food by the user (for example, the user's score for the food is equal to the user's consumption frequency of the food), or it can be determined based on the ratio of the user's consumption frequency of the food and the user's total consumption frequency. For the food that the user has not consumed, the score of the food can be 0, or the user's score for the food can be predicted by, for example, collaborative filtering recommendation algorithms, which will not be elaborated.
[0053] In some embodiments, the rating of each food in the food set by each user of the plurality of users may be represented by the following food rating matrix: , Among them, the total number of users is a, and the total number of foods in the food set is b. Indicates the a-th user's preference for the b-th food (the food can be denoted) rating.
[0054] After obtaining the user's rating of the food, the similarity between each user among the multiple users except the target user and the target user can be determined based on the rating. For example, the similarity between the target user and any other user can be determined based on the difference in the ratings of the same food by two users (including the target user and any other user). Of course, the similarity can also be determined by any existing or future developed algorithm for calculating similarity, which includes but is not limited to the Pearson correlation coefficient. In one embodiment, step S122, based on the rating of each user among the multiple users for each food in the food set, determines the similarity between each user among the multiple users except the target user and the target user, including: determining the similarity between two users by the following formula: , In the formula, Represents a collection of food items; The ath user (referred to as user a) has a preference for food Ratings; is the average score of all foods in the food set given by user a; For the bth user (referred to as user b) Ratings; is the average of the scores of all foods in the food set given by user b. In this embodiment, one of user a and user b is the target user, and the other is any other user among the multiple users except the target user, thereby calculating the similarity between each user among the multiple users except the target user and the target user.
[0055] After obtaining the similarity between each user except the target user among the multiple users and the target user, a first preset number of users may be determined based on the determined similarity. For example, the other users may be sorted from large to small according to the similarity, and the first first preset number of users may be taken as users with similar eating habits to the target user. For another example, the first preset number of users may be determined using the K nearest neighbor number. In this embodiment, K is equal to the first preset number.
[0056] The above technical solution utilizes each user's ratings of different foods to determine users with similar eating habits to the target user. The solution is simple to calculate, and this method of determining similar users using ratings can more accurately determine users with similar eating habits to the target user, which helps to provide a more accurate basis for subsequent steps, and thus helps to improve the accuracy of the final recommended recipes.
[0057] Exemplarily, for each of the multiple users, the user's dietary record also includes the user's total consumption frequency and the consumption frequency of each food consumed by the user. Step S122, based on the user's dietary record data, determines the score of each food in the food set by each of the multiple users, which can specifically include the following steps: for each of the multiple users, a first score determination operation is used to determine the user's score for the food in the food set that the user has consumed; a second score determination operation is used to determine the user's score for the food in the food set that the user has not consumed; wherein the first score determination operation includes: for each food consumed by the user, the user's score for the food is determined based on the ratio of the user's consumption frequency of the food to the user's total consumption frequency; the second score determination operation includes: for each food that the user has not consumed, the user's score for the food is determined using a collaborative filtering recommendation algorithm.
[0058] In the solution of this example, for each food consumed by the user, the user's score for the food is determined based on the ratio of the user's consumption frequency of the food to the user's total consumption frequency. Taking user a as an example, the score of user a for each food consumed can be expressed as: ,in, represents the frequency of user a's consumption of food b, Indicates the total consumption frequency of user a.
[0059] In the solution of this example, a collaborative filtering recommendation algorithm is used to predict the user's rating of uneaten food. In this way, the cold start problem caused by too little user data can be prevented. The collaborative filtering recommendation algorithm can be any existing or future developed algorithm that can predict the user's rating of unknown items. In a specific embodiment, the Slop One algorithm can be used to predict the user's rating of uneaten food. That is, the collaborative filtering recommendation algorithm is used to determine the user's rating of the food, including: determining the user's rating of the food by the following formula: , In the formula, For user a, Rating, Food Any food among the multiple foods that user a has not eaten; For user a, Ratings; Indicated food and food The preference offset between represents the set of foods consumed by user a; Representation and food A collection of foods that have an offset between Indicates the number of elements. In this embodiment, this function is used to calculate the number of items that user a has eaten and that are related to food. The number of foods that have an offset between
[0060] It can be understood that the preference offset is used to indicate the possibility that a user who has eaten a certain food will have a preference for another food. Indicates that food has been consumed of users have food The possibility of generating preferences, among which food The preference offset can be determined by using the number of users who have eaten the two foods at the same time and the ratings of the two foods by the users who have eaten the two foods.
[0061] In the above embodiment, Representation and food The set of foods that have an offset between For example, we can first confirm that multiple users have eaten food Users, Including the food consumed by these users Other foods besides.
[0062] Optionally, the preference offset can be calculated by the following formula: , In the formula, For users u to food Ratings; For users u to food Ratings; Indicates that food has been consumed at the same time and food The number of users; where user u is the number of users who have consumed food at the same time and food Any user in the user.
[0063] In the above technical solution, the score of each food in the food set given by each user among multiple users can be determined through the first score determination operation and the second score determination operation. This method can more accurately determine the score of each user for each food, thereby providing sufficient and accurate data for the determination of similar users in subsequent steps, which helps to more accurately determine users with similar eating habits to the target user.
[0064] Exemplarily, step S130, generating a pre-recommended food combination based on at least the diet records corresponding to a first preset number of users, may specifically include the following steps: determining, based on the user diet record data, the scores of a first preset number of users for each food in a food set, where the food set includes foods eaten by each of a plurality of users; calculating the average of the scores of the first preset number of users for each food in the food set to obtain an average score for each food in the food set; and determining a second preset number of foods in the food set with higher average scores to generate a pre-recommended food combination.
[0065] The specific steps of determining the user's rating of the food have been described in detail above and will not be repeated here. It can be understood that in the case where the rating of each of the multiple users for each food in the food set has been determined in step S120, the rating of each food in the food set by the first preset number of users can be directly determined based on the rating obtained in step S120. Otherwise, the first rating determination operation and the second rating determination operation described above can be used to determine the rating of each food in the food set by the first preset number of users.
[0066] In the solution of this example, the average of the scores given by a first preset number of users to each food in the food set may be determined first. The average may represent the average preference of the first preset number of users for each food in the food set.
[0067] After obtaining the average score of each food in the food set, a second preset number of foods with higher average scores can be selected to generate a pre-recommended food combination. For example, each food in the food set can be sorted from large to small according to the size of the average score, and then a second preset number of foods with higher rankings can be selected to generate a pre-recommended food combination. Of course, the second preset number of foods can also be determined by using the K nearest neighbor number. In this embodiment, K is equal to the second preset number.
[0068] The above technical solution uses the average preference of the first preset number of users for each food in the food set to select the second preset number of foods in the food set, which can ensure that the foods in the generated pre-recommended food combination are not limited to the foods that the target user has eaten, which helps to ensure the diversity of foods. And because only the ratings of the first preset number of users on the food are considered when selecting the second preset number of foods, and the ratings of the target user himself on the food are not considered, this helps to avoid the result obtained after adding the target user's dietary data from being biased (more inclined to the foods that the target user has eaten), so that the dietary diversity of the target user can be further ensured.
[0069] Exemplarily, step S130, generating a pre-recommended food combination based on at least the dietary records corresponding to a first preset number of users, may specifically include the following steps: determining, based on the user dietary record data, the scores of the target user and the first preset number of users for each food in a food set, where the food set includes foods eaten by each of multiple users; calculating the average of the scores of the target user and the first preset number of users for each food in the food set to obtain an average score for each food in the food set; determining a second preset number of foods in the food set with higher average scores to generate a pre-recommended food combination.
[0070] The specific steps for determining the user's rating of the food have been described in detail above and will not be repeated here. It can be understood that in the case where the rating of each of the multiple users for each food in the food set has been determined in step S120, the rating of each food in the food set by the target user and the first preset number of users can be directly determined based on the rating obtained in step S120. Otherwise, the first rating determination operation and the second rating determination operation described above can be used to determine the rating of each food in the food set by the target user and the first preset number of users.
[0071] In the solution of this example, the mean of the scores of the target user and the first preset number of users for each food in the food set can be first determined, and the mean can represent the average preference of the target user and the first preset number of users for each food in the food set.
[0072] After obtaining the average score of each food in the food set, a second preset number of foods with higher average scores can be selected to generate a pre-recommended food combination. For example, each food in the food set can be sorted from large to small according to the size of the average score, and then a second preset number of foods with higher rankings can be selected to generate a pre-recommended food combination. Of course, the second preset number of foods can also be determined by using the K nearest neighbor number. In this embodiment, K is equal to the second preset number.
[0073] The above technical solution uses the average preference of the target user and the first preset number of users for each food in the food set to select the second preset number of foods in the food set, which can ensure that the foods in the generated pre-recommended food combination are not limited to the foods that the target user has eaten, which helps to ensure the diversity of foods. And because the target user's rating of the food is also considered when selecting the second preset number of foods, it helps to ensure that the foods in the generated pre-recommended food combination are more in line with the user's dietary preferences, thereby helping to improve the user's experience.
[0074] Exemplarily, step S130, generating a pre-recommended food combination based on at least the dietary records corresponding to each of a first preset number of users, may specifically include the following steps: for the target user and each of the first preset number of users, determining the score of each of the foods consumed by the user based on the dietary records of the user in the user dietary record data; for the foods consumed by the target user and each of the first preset number of users, selecting a second preset number of foods with higher food scores to generate a pre-recommended food combination.
[0075] The specific steps of determining the user's rating of food have been described in detail above and will not be repeated here. It can be understood that in the case where the rating of each of the multiple users for each food in the food set has been determined in step S120, the rating of each food consumed by the target user and each of the first preset number of users can be directly determined based on the rating obtained in step S120. Otherwise, the first rating determination operation described above can be used to determine the rating of each food consumed by the target user and each of the first preset number of users.
[0076] After obtaining the scores of each food consumed by the target user and each of the first preset number of users, a second preset number of foods with higher food scores can be selected to generate a pre-recommended food combination. For example, the foods can be sorted from large to small according to the size of the average score, and then the second preset number of foods with higher rankings can be selected to generate a pre-recommended food combination. Of course, the second preset number of foods can also be determined by using the K nearest neighbor number. In this embodiment, K is equal to the second preset number.
[0077] The above technical solution uses the ratings of each food consumed by the target user and the first preset number of users to select a second preset number of foods from the foods consumed by the target user and each of the first preset number of users. This ensures that the foods in the generated pre-recommended food combination are not limited to the foods consumed by the target user, which helps to ensure the diversity of foods. And because the ratings of the target user on the food are also considered when selecting the second preset number of foods, this helps to ensure that the foods in the generated pre-recommended food combination are more in line with the user's dietary preferences, thereby helping to improve the user's experience. In addition, the solution only uses the ratings of the foods consumed by the user when determining the second preset number of foods. This is because the authenticity of the predicted ratings themselves is relatively poor. The reliability of the results obtained by only considering the ratings of the foods consumed by the user is higher, and the generated pre-recommended food combination is more accurate.
[0078] Exemplarily, step S130, generating a pre-recommended food combination based on at least the dietary records corresponding to a first preset number of users, may specifically include the following steps: for each user among the first preset number of users, determining the score of each of the foods consumed by the user based on the dietary record of the user in the user dietary record data, wherein the dietary record of the user also includes the total consumption frequency of the user and the consumption frequency of each food consumed by the user; for the foods consumed by each user among the first preset number of users, selecting a second preset number of foods with higher food scores to generate a pre-recommended food combination.
[0079] The specific steps of determining the user's rating of the food have been described in detail above and will not be repeated here. It can be understood that in the case where the rating of each of the multiple users for each food in the food set has been determined in step S120, in this example, the rating of each of the first preset number of users for each food consumed can be directly determined based on the rating obtained in step S120. Otherwise, the first rating determination operation described above can be used to determine the rating of each of the first preset number of users for each food consumed.
[0080] After obtaining the scores of each food consumed by each user among the first preset number of users, a second preset number of foods with higher food scores can be selected to generate a pre-recommended food combination. For example, the foods can be sorted from large to small according to the average score, and then the second preset number of foods with higher rankings can be selected to generate a pre-recommended food combination. Of course, the second preset number of foods can also be determined by using the K nearest neighbor number. In this embodiment, K is equal to the second preset number.
[0081] The above technical solution uses the ratings of each food consumed by the first preset number of users to select the second preset number of foods from the foods consumed by the target user and each of the first preset number of users, so that the foods in the generated pre-recommended food combination are not limited to the foods consumed by the target user, which helps to ensure the diversity of foods. And because only the ratings of the first preset number of users on the food are considered when selecting the second preset number of foods, and the ratings of the target user himself on the food are not considered, this helps to avoid the result obtained after adding the dietary data of the target user to have a tendency (more inclined to the food consumed by the target user), so as to further ensure the dietary diversity of the target user. In addition, when determining the second preset number of foods, the solution only uses the ratings of the food consumed by the user. This is because the authenticity of the predicted rating itself is poor, and the result obtained by only considering the ratings of the food consumed by the user is more reliable, and the generated pre-recommended food combination is more accurate.
[0082] Exemplarily, step S150, iteratively optimizing the population based on the objective function value of each individual in the population, may specifically include: in each iteration of the iterative optimization, taking each individual in the population as the target individual, performing individual optimization operations. The individual optimization operations may include the following steps S151, S152, S153, S154, and S155.
[0083] In step S151, the neighborhood of the target individual in the population is determined.
[0084] In step S152, based on the target individual and the individuals included in the neighborhood of the target individual, optimization is performed in sequence through a crossover operation and a polynomial mutation operation to obtain a new individual.
[0085] In step S153, the objective function values of the new individual and the target individual are compared.
[0086] In step S154, when the objective function value of the target individual is less than or equal to the new individual, the target individual is maintained unchanged.
[0087] In step S155, when the objective function value of the target individual is greater than that of the new individual, the new individual is updated to the target individual.
[0088] The neighborhood of the target individual in the population can be determined based on Euclidean distance, Manhattan distance, etc., which will not be elaborated here.
[0089] In the scheme of this example, each individual in the population is updated using individual optimization operations during each iteration of iterative optimization. Specifically, for each target individual, the target individual is evolved through crossover operations and polynomial mutation operations to obtain a new individual. Then, the objective function values between the original individual before evolution and the new individual after evolution can be compared, and the individual with the smaller objective function value is retained as the target individual. This ensures that the population always evolves in a better direction, which helps to improve the accuracy of the recommended recipes finally determined.
[0090] Optionally, determining the neighborhood of the target individual in the population may include the following steps: generating a neighborhood adjustment random number; determining whether the neighborhood adjustment random number is greater than or equal to a preset probability; when the neighborhood adjustment random number is greater than or equal to the preset probability, determining that the neighborhood of the target individual in the population is all individuals in the population except the target individual; when the neighborhood adjustment random number is less than the preset probability, determining that the neighborhood of the target individual in the population includes a preset number of individuals in the population.
[0091] Optionally, the preset probability can be set as needed, for example, to 0.1.
[0092] Optionally, the preset number can be selected according to the number of individuals in the population. For example, the preset number can be 1 / 10 of the number of individuals in the population, that is, the preset number is 1 / 10 of the third preset number. For example, if the third preset number is 100, the preset number is 10.
[0093] Optionally, determining the neighborhood of the target individual in the population may further include the following steps: when the neighborhood of the target individual in the population includes a preset number of individuals in the population, assigning a weight vector to each individual in the population; calculating the Euclidean distance between the weight vector corresponding to the target individual and the weight vector corresponding to each other individual in the population except the target individual; and determining the individuals corresponding to the preset number of weight vectors with the closest Euclidean distance to the weight vector corresponding to the target individual as the neighborhood of the target individual. For example, in one embodiment, the preset number is T. The weight vector set λ= {λ 1 , λ 2 …λ n}, the weight vectors in the weight vector set correspond one-to-one to the individuals in the population, λ 1 is the weight vector corresponding to the target individual. In this embodiment, λ can be calculated separately 1 With λ 2 …λ n The Euclidean distance between the two individuals is calculated, and then the first T individuals with the smallest Euclidean distance are determined as the individuals included in the neighborhood of the target individual, that is, the neighborhood of the target individual includes the first T individuals.
[0094] The weight vector can be obtained by using any existing or future developed weight generation method in a multi-objective evolutionary algorithm based on decomposition. Those skilled in the art can understand the specific implementation steps of the weight generation method in the multi-objective evolutionary algorithm based on decomposition, and will not repeat them. It can be understood that the weight vector is a set of uniformly distributed vectors, such as optimizing three objectives, and the distribution of the weight vector is in the space of {0,0,1}, {0,1,0}, {0,0,1}. In the scheme of this example, the target number is the same as the number of nutritional elements in the nutritional ingredients. In the embodiment in which the above-mentioned nutritional ingredients include nine kinds of nutritional elements, the target number is 9. The number of weight values of the weight vector is consistent with the optimization target. This example is equivalent to assigning a weight to each individual by assigning a weight vector to each individual, so as to realize the decomposition strategy. Thus, the neighborhood of the target individual can be determined more accurately, and the individuals in the determined neighborhood have similar target characteristics to the target individual. In this case, the subsequent iterative optimization steps can help the individual to better explore the local optimal solution and improve the accuracy of the search.
[0095] Exemplarily, before performing the crossover operation, the individual optimization operation further includes: determining an evolution strategy for the crossover operation based on preset conditions; wherein the evolution strategy includes a differential evolution (DE) operator and a simulated binary crossover (SBX) operator. The crossover operation is performed based on the determined evolution operation. Those skilled in the art can understand the specific operation process of the DE operator and the SBX operator, which will not be described in detail.
[0096] The preset condition can be determined according to actual needs. In some embodiments, the preset condition can be: when the crossover selection random number is less than p, the DE operator is selected; otherwise, the SBX operator is selected. The crossover selection random number can be generated before each crossover operation is performed.
[0097] In other embodiments, the preset condition may be to select the DE operator or the SBX operator according to the number of current iterations. For example, the preset condition may be: when the current number of iterations is an odd number, the evolution strategy is the DE operator, and when the current number of iterations is an even number, the evolution strategy is the SBX operator. For another example, the preset condition may be: when the current number of iterations is less than a preset number threshold, the evolution strategy is the SBX operator; otherwise, the evolution strategy is the DE operator.
[0098] In some other embodiments, the preset condition may be to determine the evolution strategy of the crossover operation according to the degree of the current population update evolution, that is, when the degree of the current population update evolution is less than or equal to the preset degree threshold, the evolution strategy is the SBX operator; when the degree of the current population update evolution is greater than the preset degree threshold, the evolution strategy is the DE operator. The preset degree threshold can be determined according to actual needs and will not be described in detail. The degree of population update evolution can be determined according to the number of individuals that have changed in the population. It can be understood that when the new individual is updated as the target individual in the above embodiment, the number of individuals that have changed in the population is +1.
[0099] Of course, in the following embodiment using the neighbor update operation, the degree of population update evolution can also be determined according to the number of updates of neighbor individuals (i.e., the number of changes of neighbor individuals). For example, in this embodiment, the degree of population update evolution is the number of updates of neighbor individuals. The number of updates of neighbor individuals is represented by N, and the preset degree threshold is N. m When N≤N m When N>N, the evolution strategy is SBX operator, that is, the SBX operator is used to complete the crossover operation; when N>N m When , the evolution strategy is the DE operator, that is, the DE operator is used to complete the crossover operation. This scheme uses the DE operator when the degree of population update evolution is better, and uses the SBX operator when the degree of population update evolution is worse. In this way, the degree of population update evolution can be used to guide the selection of the evolution strategy, thereby guiding the population to evolve in a better direction.
[0100] It can be understood that the DE operator has a strong local search capability and a relatively fast convergence speed, but it is poor in maintaining population diversity and is prone to premature convergence. The SBX operator can better maintain the diversity of the population and performs better when dealing with complex problems, but it converges slowly. The above technical solution uses an evolutionary strategy of competition between the DE operator and the SBX operator to complete the crossover operation in each iteration process, which can ensure that there is both exploration (exploring new search spaces) and development (fine search in known areas) in the population, thereby increasing the diversity of the population and avoiding premature convergence. This method helps to improve the accuracy of the recommended recipes finally determined.
[0101] Optionally, the operation process of the DE operator includes: firstly, generating a random 01 coding sequence, and corresponding the 01 numbers in the sequence to two randomly selected neighboring gene positions (it can be understood that the consumption amount corresponding to each food in an individual is a gene position). If the sequence number is 0, the value of the corresponding gene position is not obtained, and if the sequence number is 1, the value of the corresponding gene position is obtained, and then a crossover operation is performed, and the calculation formula is as follows: , In the formula, represents the original individual (i.e., the target individual); and Respectively represent two neighbor individuals, and the two neighbor individuals are any two individuals in the neighborhood of the target individual; represents the newly generated individuals through crossover; Represents the crossover amplitude, the size of which can be determined as needed, for example, it can be 0.5.
[0102] Optionally, the operation of the SBX operator includes generating a random number r between 0 and 1 c , used to set the crossover probability p c To determine whether to perform a crossover operation, for each gene position to be crossed, if r c <p c , then perform the crossover operation: (1) Calculation of auxiliary variables , the calculation formula is: , in, is a random number between 0 and 1; is a constant representing the distribution index. When larger, offspring tend to resemble their parents more.
[0103] (2) Calculate the value of the offspring gene position. The calculation formula is: , in, represents the original individual (i.e., the target individual); represents a neighbor individual, which is any individual in the neighborhood of the target individual; Represents the newly generated individuals through crossover.
[0104] The above briefly describes the operation process of the DE operator and the SBX operator. Those skilled in the art can understand the specific steps of performing the crossover operation based on the DE operator or the SBX operator, which will not be described in detail.
[0105] Optionally, the operation process of the polynomial mutation operation is as follows: suppose that a certain gene value x (this gene value is the value of the gene position. For example, the crossover individual is {1, 2, 3, 4, 5, 6}, and these 6 numbers are the gene values of the crossover individual) obtained by the crossover operation is to be subjected to polynomial mutation. First, determine the distribution index of the diversity mutation and mutation probability d m Then, generate a random number r between 0 and 1 m , if r m ≤ d m , then polynomial mutation is performed, otherwise polynomial mutation is not performed.
[0106] When performing polynomial mutation, a random number r is generated again between 0 and 1. If r ≤ 0.5, the mutation increment is calculated using the following formula: ; If r>0.5, the variation increment is calculated using the following formula: ; The mutated gene value y is determined using the following formula: .
[0107] The above briefly describes the operation process of the polynomial mutation operation. Those skilled in the art can understand the specific steps and application methods of the polynomial mutation operation, which will not be described in detail.
[0108] Exemplarily, before performing the polynomial mutation operation, the method further includes: adjusting the mutation probability of the polynomial mutation operation based on the current number of iterations and the iteration number threshold, wherein the mutation probability increases with the increase of the number of iterations.
[0109] The above operation can be referred to as a mutation probability adjustment operation. Optionally, the mutation probability adjustment operation is performed before the first individual optimization operation of each iteration process is performed. It can be understood that in each iteration process, the third preset number of individual optimization operations are performed. Since the mutation probability of the polynomial mutation operation is performed based on the current number of iterations and the iteration number threshold, that is to say, the mutation probability of the polynomial mutation operation in each individual optimization operation performed in an iteration process is the same. In the scheme of this example, before performing the first individual optimization operation, the mutation probability of the polynomial mutation operation in the current iteration process is determined in advance by the mutation probability adjustment operation, so that there is no need to repeatedly determine the mutation probability in the subsequent process, which helps to improve the efficiency of iterative optimization.
[0110] In some embodiments, the mutation probability can be increased linearly according to the increase in the number of iterations. In other embodiments, the mutation probability can also be adjusted nonlinearly and randomly. In this embodiment, the mutation probability can be adjusted using the following formula: : , in, and are the upper and lower limits of the mutation probability, for example, they can be 0.2 and 0.1 respectively; i is the current iteration number; is the maximum number of iterations (i.e., the iteration number threshold); is a chaotic Sine map; rand is a random number between 0 and 1; A random number between 0 and 1, which is related to the amplitude of the above function formula.
[0111] The above technical solution can achieve dynamic adjustment of the mutation probability by adjusting the mutation probability of the polynomial mutation operation (for example, nonlinear random adjustment), ensuring that the overall change trend of the mutation probability gradually increases with the evolution of the population. This helps to increase the search capability in the later stage of iteration and increase the randomness of evolution, which in turn helps to maintain the diversity of the population and prevent premature convergence to the local optimal solution.
[0112] Exemplarily, before comparing the objective function values of the new individual with those of the target individual, the individual optimization operation also includes: for each consumption amount in the new individual, determining whether the consumption amount is within a preset consumption amount range; when the consumption amount is greater than the upper limit of the preset consumption amount range, adjusting the consumption amount to the upper limit of the preset consumption amount range; when the consumption amount is less than the lower limit of the preset consumption amount range, adjusting the consumption amount to the lower limit of the preset consumption amount range. The steps of this example may be referred to as an out-of-bounds processing operation. In the step of "comparing the objective function values of the new individual with those of the target individual", the new individual is a new individual processed by the out-of-bounds processing operation.
[0113] In the solution of this example, the preset serving size range can be determined according to the user's situation. For example, the preset serving size range can be [10g, 400g].
[0114] In this example, after generating new individuals using crossover and polynomial mutation operations, we can first determine whether the consumption amount corresponding to each food in the new individual (i.e., each gene value of the new individual) is within the preset consumption amount range. When any gene value is not within the preset consumption amount range, the gene value can be adjusted to make it within the preset consumption amount range. This can prevent the problem of excessive consumption of a single food in order to reduce errors during the iterative optimization of the population, and ensure the rationality of the individual. Exemplarily, before the first iteration of the iterative optimization, the method further includes: initializing an ideal individual to obtain an initial ideal individual, where the initial ideal individual is any individual in the population.
[0115] After each individual optimization operation is completed, the method may further include the following steps: comparing the objective function value of the current target individual (i.e., the target individual corresponding to the current individual optimization operation) with the objective function value of the current ideal individual; when the objective function value of the current target individual is less than the objective function value of the current ideal individual, updating the current target individual to the ideal individual. That is, the updated ideal individual is the same as the current target individual.
[0116] In the scheme of this example, step S160, when the number of iterative optimization reaches the iteration number threshold, generates a recommended recipe for the target user based on the individual with the smallest objective function value in the current population, which may include the following steps: when the number of iterative optimization reaches the iteration number threshold, generates a recommended recipe for the target user based on the current ideal individual.
[0117] As mentioned above, the initial ideal individual is any individual in the population, for example, the first individual in the initial population.
[0118] In the scheme of this example, the current target individual is compared with the ideal individual after each individual optimization operation. In this way, the objective function values of the ideal individual and the individuals at each position in the population can be compared respectively to ensure that the ideal individual always corresponds to the individual with the smallest objective function value in the current population. In this case, the ideal individual corresponding to the last iteration is the individual with the smallest objective function value in the population obtained in the last iteration.
[0119] Exemplarily, the method also includes: in each iteration of iterative optimization, for the first fourth preset number of individual optimization operations performed in the current iteration, after each individual optimization operation is completed, performing the following neighbor update operation: randomly selecting an individual in the neighborhood of the current target individual as a neighbor individual, the current target individual being the target individual corresponding to the current individual optimization operation; comparing the objective function value of the neighbor individual with that of the current target individual; when the objective function value of the current target individual is less than that of the neighbor individual, using the current target individual to update the neighbor individual; wherein the updated neighbor individual is the same as the current target individual.
[0120] The fourth preset number can be set as needed and will not be described in detail. In the scheme of this example, the neighbor update operation is executed a fourth preset number of times. In some implementation schemes, for the first fourth preset number of individual optimization operations in each iteration process, the neighbor update operation can be executed after each individual optimization operation is completed. In other implementation schemes, in each iteration process, the neighbor update operation can be executed after each individual optimization operation is completed, and the number of executions of the neighbor update operation in the current iteration process is accumulated. When the number of executions of the neighbor update operation reaches the fourth preset number, the operation is stopped. For example, if the fourth preset number is n r In this embodiment, the neighbor update operation can be performed after each individual optimization operation is completed until the number of executions of the neighbor update operation reaches n. r Up to times.
[0121] The above technical solution performs a neighbor update operation after the fourth preset number of individual optimization operations in each iteration process, so that the population can be guided to evolve in a more optimal direction by updating the neighbor individuals. At the same time, the neighbor update operation is only performed for the fourth preset number of times in each iteration process, which can prevent the individuals in the population from being too similar due to excessive execution of the neighbor update operation. In short, the solution can make the population evolve in a more optimal direction while ensuring the diversity of the population, thereby helping to further improve the accuracy of the recommended recipes finally determined.
[0122] Exemplarily, after the new individual is updated as the target individual, the individual optimization operation further includes: comparing the content of each nutrient element in the nutrient content of the target individual with the standard content of the corresponding nutrient element to determine an overnutrition set and an undernutrition set, the overnutrition set includes the nutrient elements with a content greater than the standard content among the multiple nutrient elements corresponding to the target individual, and the undernutrition set includes the nutrient elements with a content less than the standard content among the multiple nutrient elements corresponding to the target individual; randomly selecting a nutrient element from the overnutrition set, and based on a first preset step value, reducing the consumption of a food corresponding to the nutrient element in the target individual (for the convenience of distinction, the food is referred to as the first food to be adjusted); randomly selecting a nutrient element from the undernutrition set, and based on a second preset step value, increasing the consumption of a food corresponding to the nutrient element in the target individual (for the convenience of distinction, the food is referred to as the second food to be adjusted); comparing the objective function value of the individual obtained after adjustment with the objective function value of the target individual; when the objective function value of the individual obtained after adjustment is less than that of the target individual, updating the individual obtained after adjustment to the target individual. For the convenience of distinction, the individual obtained after adjustment can be referred to as an adaptive individual.
[0123] In this example, the content of each nutrient element in the nutrient content of the target individual can be compared with the standard content of the corresponding nutrient element, and statistics can be performed by two sets, namely, the excess nutrient set and the insufficient nutrient set. For example, the excess nutrient set is PN, the insufficient nutrient set is NN, and the nutrient elements include calories, protein, fat, carbohydrates, vitamin A, vitamin B, calcium, iron, and vitamin C. In this embodiment, when the content of a certain nutrient element of the target individual is greater than the standard content of the nutrient element, the nutrient element is added to PN, and when the content of a certain nutrient element of the target individual is less than the standard content of the nutrient element, the nutrient element is added to NN.
[0124] After determining the excess nutrition set and the insufficient nutrition set, a nutrient element can be randomly selected from each of the two sets, and then a food corresponding to the nutrient element can be determined. In some embodiments, the food corresponding to the nutrient element can be any food containing the nutrient element in the pre-recommended food combination. In other embodiments, the food corresponding to the nutrient element can be the food containing the most nutrient element in the pre-recommended food combination.
[0125] After determining a food corresponding to the nutrient element, the consumption amount corresponding to the food in the target individual can be adjusted. Among them, in step S172, the consumption amount corresponding to the food can be reduced according to the first preset step value. In step S173, the consumption amount corresponding to the food can be increased according to the second preset step value. In this example, the first preset step value and the second preset step value can be the same or different. The specific sizes of the first preset step value and the second preset step value can be set as needed and are not repeated. In a specific embodiment, the first preset step value and the second preset step value can both be 5g.
[0126] Optionally, the first food to be adjusted and the second food to be adjusted are two different foods. In the above embodiment where the food corresponding to the nutrient element is the food with the most nutrient element in the pre-recommended food combination, if the nutrient element selected in the excess nutrition set is the same as the food corresponding to the nutrient element selected in the undernutrition set, then the next food can be selected from one of the sets. For example, if the food corresponding to the nutrient element selected in the excess nutrition set and the nutrient element selected in the undernutrition set are both food A, in this case, the food corresponding to the nutrient element selected in the undernutrition set can select the food containing the second richest nutrient element (e.g., food B). That is, the first food to be adjusted is food A, and the second food to be adjusted is food B.
[0127] After the intake amount corresponding to the first food to be adjusted and the second food to be adjusted in the target individual is adjusted, the objective function value of the adaptive individual obtained after adjustment can be compared with the objective function value of the current target individual, and the individual with the smaller objective function value can be retained as the target individual.
[0128] The above technical solution can make targeted adjustments to the nutritional balance of food for the target individual based on the difference between the nutrient content of the target individual and the standard content, which helps to generate recommended recipes that are more nutritionally balanced and can better meet the nutritional needs of users.
[0129] Optionally, after the individual obtained after adjustment is updated as the target individual, it is also possible to determine whether the consumption of the food in the target individual is within the preset consumption range; when the consumption of the food in the target individual is greater than the upper limit of the preset consumption range, the consumption of the food in the target individual is adjusted to the upper limit of the preset consumption range; when the consumption of the food in the target individual is less than the lower limit of the preset consumption range, the consumption of the food in the target individual is adjusted to the lower limit of the preset consumption range. The specific implementation method of this scheme is similar to the execution steps of the cross-border processing operation mentioned above, and will not be repeated.
[0130] Through a specific embodiment of the present application, the mixed food recommendation method of the present application and other algorithms are used to generate recommended recipes based on real data, and the obtained recommended recipes are compared to further describe the present application.
[0131] In this embodiment, the method includes the following steps: first, obtaining user dietary record data, and constructing a food rating matrix based on the user dietary record data, so as to determine a first preset number of users whose dietary habits are similar to those of a target user among a plurality of users based on the user's ratings of the food. Then, for the food consumed by each user among the first preset number of users, a second preset number of foods with higher food ratings are selected to generate a pre-recommended food combination. Next, the population and the ideal individual are initialized. After the population is initialized, the population is iteratively optimized using the individual optimization operation. Wherein, after each individual optimization operation is executed, the ideal individual is updated. Finally, after the number of iterative optimizations reaches the iteration number threshold, a recommended recipe for the target user is generated based on the ideal individual.
[0132] The test data of this embodiment comes from MyFitnessPal (MFP), a popular health and fitness tracking application, which records the user's daily diet and exercise. This experiment uses the hybrid food recommendation method of this embodiment to tune the food combination, and compares it with the multi-objective particle swarm (MOPSO) algorithm, the multi-objective evolutionary algorithm based on decomposition (MOEA / D), the multi-objective artificial bee colony (MOABC) algorithm, and the reference vector guided multi-objective optimization evolutionary algorithm (RVEA).
[0133] In this embodiment, the population size (ie, the third preset number) is 120, the iteration number threshold is 150, the initial neighborhood size (ie, the preset number) is 12, and the crossover probability p is c is 0.5, the distribution index is 20, the fourth preset number n r is 2.
[0134] In order to better evaluate the recommended recipes generated by the method of the present application, this embodiment uses the difference between the nutrient content of the recommended recipe and the standard nutrient content as a judgment indicator to judge the quality of the generated recommended recipe. The specific results are shown in Table 1.
[0135] Table 1 Difference between the nutritional content of the recommended recipes and the nutritional content of the standard recipes
[0136] As shown in Table 1, the errors of most nutrients contained in the recommended recipes obtained by the method of the present application are kept within 15%, which can meet the daily nutritional needs of the target users.
[0137] Table 2 Comparison of results of various algorithms
[0138] As can be seen from Table 2, compared with other algorithms, this scheme has a lower average error and a more balanced tuning result of various nutrient elements.
[0139] Figure 2 A schematic diagram of the nutritional tuning process of an embodiment of the present application and multiple existing schemes (multi-objective particle swarm algorithm, multi-objective evolutionary algorithm based on decomposition, multi-objective artificial bee colony algorithm and reference vector guided multi-objective optimization evolutionary algorithm) is shown. In this embodiment, the change in the error sum between the nutrient content of the ideal individual and the standard nutrient content in each iteration is used to represent the convergence speed. Figure 2 It can be seen that, compared with other algorithms, the solution of this embodiment converges faster during the iterative optimization process, and the nutritional error of the recommended recipes finally obtained is lower.
[0140] In summary, the method of the present application has superior performance compared to other algorithms, and can provide a more complete solution when faced with food recommendation problems. This can also prove the effectiveness of the method of the present application in solving the problem of nutritional balance in daily diet.
[0141] According to another aspect of the embodiments of the present application, an electronic device is also provided. Figure 3 FIG. 1 is a schematic block diagram of an electronic device according to an embodiment of the present application. Figure 3 As shown, the electronic device 300 includes: a processor 310 and a memory 320. The memory 320 stores a computer program, and the processor 310 is used to execute the computer program to implement the above method.
[0142] According to another aspect of the embodiment of the present application, a computer-readable storage medium is also provided. The storage medium stores a computer program / instruction, and the computer program / instruction implements the above method when executed by the processor. The storage medium may include, for example, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer-readable storage medium may be any combination of one or more computer-readable storage media.
[0143] A person skilled in the art can easily understand the implementation structure, working principle and beneficial effects of the electronic device and the computer-readable storage medium by reading the above mixed food recommendation method. For the sake of brevity, it will not be described in detail here.
[0144] Although the exemplary embodiments have been described herein with reference to the accompanying drawings, it should be understood that the exemplary embodiments described above are merely exemplary and are not intended to limit the scope of the present application thereto. A person of ordinary skill in the art may make various changes and modifications therein without departing from the scope and spirit of the present application.
[0145] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0146] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.
[0147] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0148] Similarly, it should be understood that in order to streamline the present application and assist in understanding one or more of the various aspects of the application, in the description of exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof.
[0149] Those skilled in the art will appreciate that, except for mutually exclusive features, all features disclosed in this specification and all processes or units of any method or device disclosed in this specification may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification may be replaced by an alternative feature that provides the same, equivalent or similar purpose.
[0150] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the present application and to form different embodiments.
[0151] The various component embodiments of the present application may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all functions of some modules in the electronic device according to the embodiment of the present application. The present application may also be implemented as a device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program implementing the present application may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0152] The above description is only a specific implementation method or an explanation of a specific implementation method of the present application, and the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.
Claims
1. A mixed food recommendation method, characterized in that: include: Acquire user diet record data, wherein the user diet record data includes diet records of multiple users, the multiple users include a target user, and for each user among the multiple users, the diet record of the user includes food consumed by the user; Based on the user diet record data, determining a first preset number of users among the multiple users whose diet habits are similar to the target user; generating a pre-recommended food combination according to at least the dietary records corresponding to the first preset number of users, wherein the pre-recommended food combination includes a second preset number of foods; Initializing a population based on the pre-recommended food combination, wherein the population includes a third preset number of individuals, each of the third preset number of individuals corresponds to a different consumption amount combination, and the consumption amount combination includes consumption amounts corresponding to the second preset number of foods one by one; Iteratively optimizing the population based on the objective function value of each individual in the population, wherein the objective function is the difference between the nutrient content of the corresponding individual and the standard nutrient content, the nutrient content includes a plurality of nutrient elements, and the standard nutrient content includes standard contents corresponding to the plurality of nutrient elements one by one; When the number of iterations of the optimization reaches a threshold number of iterations, a recommended recipe for the target user is generated based on the individual with the smallest objective function value in the current population; The recommended recipe includes the pre-recommended food combination and the consumption combination corresponding to the individual with the smallest objective function value.
2. The mixed food recommendation method according to claim 1, characterized in that: The determining, based on the user diet record data, a first preset number of users among the plurality of users whose diet habits are similar to that of the target user comprises: Determine, based on the user diet record data, a score of each of the plurality of users for each food in a food set, wherein the food set includes the food consumed by each of the plurality of users; Determine the similarity between each user among the multiple users except the target user and the target user according to the score given by each user among the multiple users to each food in the food set; Based on the similarity between each user among the multiple users except the target user and the target user, a first preset number of users among the multiple users whose eating habits are similar to that of the target user are determined.
3. The mixed food recommendation method according to claim 2, characterized in that: For each user among the plurality of users, the dietary record of the user further includes the total consumption frequency of the user and the consumption frequency of each food consumed by the user; The step of determining, based on the user diet record data, a score of each of the plurality of users for each food in the food set comprises: For each user of the plurality of users, Using a first rating determination operation to determine the rating of the user on the food in the food set that the user has consumed; Using a second score determination operation to determine the user's score for the food in the food set that the user has not consumed; The first score determination operation includes: for each food consumed by the user, determining the score of the food by the user based on the ratio of the frequency of consumption of the food by the user to the total frequency of consumption of the food by the user; The second rating determination operation includes: for each food that the user has not eaten, using a collaborative filtering recommendation algorithm to determine the user's rating of the food.
4. The mixed food recommendation method according to claim 1, characterized in that: The generating of the pre-recommended food combination according to at least the dietary records corresponding to the first preset number of users includes: Based on the user diet record data, determining the scores of the first preset number of users on each food in the food set, where the food set includes the food consumed by each of the plurality of users; Calculating the average of the scores given by the first preset number of users to each food in the food set to obtain an average score for each food in the food set; Determining a second preset number of foods with higher average scores in the food set to generate the pre-recommended food combination; or, Based on the user diet record data, determining the score of each food in a food set given by the target user and the first preset number of users, wherein the food set includes the food consumed by each of the multiple users; Calculating the average of the scores given by the target user and the first preset number of users to each food in the food set, so as to obtain an average score for each food in the food set; Determining a second preset number of foods with higher average scores in the food set to generate the pre-recommended food combination; or, For each of the target user and the first preset number of users, based on the diet record of the user in the user diet record data, determining a score of each of the foods consumed by the user by the user; For the foods consumed by the target user and each of the first preset number of users, a second preset number of foods with higher food scores are selected to generate the pre-recommended food combination; or, For each user among the first preset number of users, based on the diet record of the user in the user diet record data, determining the score of each food consumed by the user, wherein the diet record of the user also includes the total consumption frequency of the user and the consumption frequency of each food consumed by the user; For the food consumed by each of the first preset number of users, a second preset number of foods with higher food scores are selected to generate the pre-recommended food combination.
5. The mixed food recommendation method according to any one of claims 1 to 4, characterized in that: The iterative optimization of the population based on the objective function value of each individual in the population includes: In each iteration of the iterative optimization, each individual in the population is taken as a target individual, and the following individual optimization operations are performed: Determining a neighborhood of the target individual in the population; Based on the target individual and individuals included in the neighborhood of the target individual, optimizing by crossover operation and polynomial mutation operation in sequence to obtain a new individual; Comparing the objective function values of the new individual and the target individual; When the objective function value of the target individual is less than or equal to the new individual, maintaining the target individual unchanged; When the objective function value of the target individual is greater than that of the new individual, the new individual is updated to be the target individual.
6. The mixed food recommendation method according to claim 5, characterized in that: Before comparing the objective function values of the new individual with those of the target individual, the individual optimization operation further includes: For each serving size in the new individual, Determine whether the consumption amount is within a preset consumption amount range; When the consumption amount is greater than the upper limit of the preset consumption amount range, adjusting the consumption amount to the upper limit of the preset consumption amount range; When the consumption amount is less than the lower limit of the preset consumption amount range, the consumption amount is adjusted to the lower limit of the preset consumption amount range.
7. The mixed food recommendation method according to claim 5, characterized in that: The method further comprises: In each iteration of the iterative optimization, for the first fourth preset number of individual optimization operations performed in the current iteration, after each individual optimization operation is completed, the following neighbor update operation is performed: Randomly select an individual in the neighborhood of the current target individual as a neighbor individual, wherein the current target individual is the target individual corresponding to the current individual optimization operation; Comparing the objective function values of the neighbor individual and the current target individual; When the objective function value of the current target individual is smaller than that of the neighbor individual, using the current target individual to update the neighbor individual; The updated neighbor individual is the same as the current target individual.
8. The mixed food recommendation method according to claim 5, characterized in that: After the new individual is updated as the target individual, the individual optimization operation further includes: Comparing the content of each nutrient element in the nutrient content of the target individual with the standard content of the corresponding nutrient element to determine an overnutrition set and an undernutrition set, wherein the overnutrition set includes nutrient elements with a content greater than the standard content among the multiple nutrient elements corresponding to the target individual, and the undernutrition set includes nutrient elements with a content less than the standard content among the multiple nutrient elements corresponding to the target individual; Randomly selecting a nutrient element from the excess nutrient set, and reducing the consumption of a food corresponding to the nutrient element in the target individual based on a first preset step value; Randomly selecting a nutrient element from the nutritional deficiency set, and increasing the consumption of a food corresponding to the nutrient element in the target individual based on a second preset step value; Comparing the objective function value of the individual obtained after adjustment with the objective function value of the target individual; When the objective function value of the individual obtained after the adjustment is less than the target individual, the individual obtained after the adjustment is updated to the target individual.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program, and the processor is used to execute the computer program to implement the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: A computer program / instruction is stored, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Personalized healthy diet recommendation service method
CN105677852A
Diet recommendation system based on big data analysis
CN111599440A
Diet information recommendation method and device, electronic equipment and medium
CN111881341A
Multi-food material nutrition proportioning method based on genetic algorithm
CN112069382A
Recipe determination method and system, storage medium and electronic equipment
CN115019937A
