Terminal device and music generation method
By employing a multi-population co-evolutionary algorithm, combined with particle swarm optimization and genetic algorithms for iterative evolution, the problems of low music generation quality and slow speed were solved, achieving high-quality and rapid generation of diverse music.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-12
- Publication Date
- 2026-03-03
AI Technical Summary
Existing technologies suffer from low quality and slow speed in music generation. In particular, music generated based on user-defined rules and templates lacks adaptability and creativity, music generated based on genetic algorithms has slow convergence speed and low quality, and music generated based on machine learning and deep learning requires a large amount of training data and time to achieve good results.
Music is generated using a multi-population co-evolution approach. An initial population is created by setting an evaluation index function and constraints. The first and second populations are iteratively evolved using a particle swarm optimization algorithm and a genetic algorithm based on an elite preservation strategy, respectively. Exchange operations are performed at preset intervals of a number of iterations to finally generate target music with a fitness function value greater than a preset threshold.
It improves the quality and speed of music generation, enables a more comprehensive search of the solution space, and generates diverse and richer music.
Smart Images

Figure CN118942434B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of audio processing technology, and in particular to a terminal device and a music generation method. Background Technology
[0002] Music comprises basic elements such as dynamics, tonality, duration, and timbre. These elements combine to form formal musical elements, such as rhythm, melody, harmony, dynamics, tempo, mode, form, and texture. Its medium is regularly organized, time-controlled sound waves. Different musical genres possess different formal elements and can be categorized based on their rhythmic qualities, such as folk, pop, rock, rap, and classical music.
[0003] Music can be generated based on user-defined rules and templates, but this method lacks adaptability and creativity, making it difficult to produce diverse and rich music. Algorithms can also be used to generate music, such as genetic algorithms. However, genetic algorithms have slow convergence speeds, reducing the speed of music generation, and the quality of the generated music is relatively low. Alternatively, music can be generated using machine learning and deep learning algorithms. These algorithms can automatically derive new music, resulting in more diverse and richer music with higher quality. However, these algorithms require a large amount of training data and time to achieve good results. Summary of the Invention
[0004] This application provides a terminal device and a music generation method to solve the problems of low music generation quality and slow speed.
[0005] In a first aspect, this application provides a terminal device, including: an audio output interface and a controller; wherein the audio output interface is configured to play music; and the controller is configured to execute the following program steps:
[0006] Set the evaluation index function and constraints;
[0007] Create an initial population, which includes a first population and a second population;
[0008] The first population is iteratively evolved using a first algorithm, and the second population is iteratively evolved using a second algorithm;
[0009] At a preset interval of iterations, an exchange operation is performed on individuals in the first population and individuals in the second population;
[0010] Generate target music, wherein the target music is an individual whose fitness function value is greater than a preset fitness threshold when the number of iterations equals the iteration threshold, and the fitness function value is calculated based on the evaluation index function and the constraint conditions.
[0011] Secondly, this application also provides a music generation method, the method comprising:
[0012] Set the evaluation index function and constraints;
[0013] Create an initial population, which includes a first population and a second population;
[0014] The first population is iteratively evolved using a first algorithm, and the second population is iteratively evolved using a second algorithm;
[0015] At a preset interval of iterations, an exchange operation is performed on individuals in the first population and individuals in the second population;
[0016] Generate target music, wherein the target music is an individual whose fitness function value is greater than a preset fitness threshold when the number of iterations equals the iteration threshold, and the fitness function value is calculated based on the evaluation index function and the constraint conditions.
[0017] As can be seen from the above technical solutions, this application provides a terminal device and a music generation method. The method can set an evaluation index function and constraints for music generation, and create an initial population, which includes a first population and a second population. Then, a first algorithm is used to iteratively evolve the first population to iteratively search for the optimal individual within it, and a second algorithm is used to iteratively evolve the second population to iteratively search for the optimal individual within it. Furthermore, at preset iteration intervals, individuals in the first and second populations are swapped. Finally, a target music is generated based on the results of the iterative evolution. The target music is defined as individuals whose fitness function value is greater than a preset fitness threshold when the number of iterations equals an iteration threshold. The fitness function value is calculated based on the evaluation index function and constraints. This method uses a multi-population co-evolution approach to generate music, which can more comprehensively search the solution space, thereby improving the quality and speed of music generation. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 A schematic diagram of the system architecture of the terminal device provided in the embodiments of this application;
[0020] Figure 2 This is a schematic diagram of the hardware configuration of the terminal device provided in the embodiments of this application;
[0021] Figure 3 This is a schematic diagram illustrating the playback of audio data in an embodiment of this application;
[0022] Figure 4 This is a flowchart illustrating the music generation method in an embodiment of this application;
[0023] Figure 5 This is a schematic diagram illustrating the process of multi-population evolution in the embodiments of this application;
[0024] Figure 6 This is a schematic diagram of the process of iteratively evolving the first population using the particle swarm optimization algorithm in an embodiment of this application;
[0025] Figure 7 This is a schematic diagram illustrating the process of iteratively evolving the second population using a genetic algorithm in an embodiment of this application.
[0026] Figure 8 This is a flowchart illustrating the process of retaining individuals with higher fitness function values in an embodiment of this application.
[0027] Figure 9 This is a schematic diagram illustrating the process of iteratively evolving the second population using a genetic algorithm based on an elite preservation strategy in an embodiment of this application.
[0028] Figure 10 This is a schematic diagram of the exchange operation in an embodiment of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of the exemplary embodiments of this application clearer, the technical solutions in the exemplary embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described exemplary embodiments are only some embodiments of this application, and not all embodiments.
[0030] Based on the exemplary embodiments shown in this application, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this application. Furthermore, although the disclosures in this application are presented by way of one or more exemplary examples, it should be understood that each aspect of these disclosures can constitute a complete technical solution on its own.
[0031] It should be understood that the terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate, for example, to allow implementation in orders other than those given in the embodiments illustrated or described in this application.
[0032] Furthermore, the terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclusively include, for example, a product or device that includes a series of components is not necessarily limited to those that are explicitly listed, but may include other components that are not explicitly listed or that are inherent to such product or device.
[0033] Figure 1 An exemplary system architecture for which the audio localization method and terminal device of this application can be applied is shown. Figure 1 As shown, 10 is a server and 200 is a terminal device, including (smart TV 200a, mobile device 200b, smart speaker 200c).
[0034] In this application, server 10 and terminal device 200 communicate data through various communication methods. Terminal device 200 can be connected via local area network (LAN), wireless local area network (WLAN), and other networks. Server 10 can provide various content and interactive features to terminal device 200. For example, terminal device 200 and server 10 can send and receive information, and receive software updates.
[0035] Server 10 can be a server that provides various services, such as a backend server that supports audio data collected by terminal device 200. The backend server can analyze and process the received audio and other data, and feed back the processing results (such as endpoint information) to the terminal device. Server 10 can be a server cluster or multiple server clusters, and can include one or more types of servers.
[0036] The terminal device 200 can be either hardware or software. When the terminal device 200 is hardware, it can be various electronic devices with sound acquisition capabilities, including but not limited to smart speakers, smartphones, televisions, tablets, e-book readers, smartwatches, media players, computers, AI devices, robots, smart vehicles, etc. When the terminal device 200 is software, it can be installed in the electronic devices listed above. It can be implemented as multiple software programs or software modules (e.g., used to provide sound acquisition services) or as a single software program or software module. No specific limitations are imposed here.
[0037] It should be noted that the music generation method provided in this application embodiment can be executed by server 10, by terminal device 200, or by both server 10 and terminal device 200. This application does not limit the execution of this method.
[0038] Figure 2 A hardware configuration block diagram of a terminal device 200 according to an exemplary embodiment is shown. For example... Figure 2The terminal device 200 shown includes at least one of the following: a communicator 220, a detector 230, an external device interface 240, a controller 250, a display 260, an audio output interface 270, a memory, a power supply, and a user interface 280. The controller includes a central processing unit, an audio processor, a graphics processor, RAM, ROM, and a first to an nth interface for input / output.
[0039] The display 260 includes a display screen assembly for presenting images, a driving assembly for driving image display, a component for receiving image signals from the controller output, and a user control UI interface for displaying video content, image content, menu control interface, and user control UI interface.
[0040] The display 260 can be an LCD display, an OLED display, or a projection display, and can also be a projection device and a projection screen.
[0041] The communicator 220 is a component used to communicate with external devices or servers according to various communication protocol types. For example, the communicator may include at least one of the following: a Wi-Fi module, a Bluetooth module, a wired Ethernet module, other network communication protocol chips or near-field communication protocol chips, and an infrared receiver. The terminal device 200 can establish the transmission and reception of control signals and data signals through the communicator 220.
[0042] The user interface can be used to receive external control signals.
[0043] Detector 230 is used to collect signals from the external environment or to interact with the external environment. For example, detector 230 includes a light receiver, a sensor for collecting ambient light intensity; or, detector 230 includes an image acquisition device, such as a camera, which can be used to collect external environmental scenes, user attributes, or user interaction gestures; or, detector 230 includes a sound acquisition device, such as a microphone, for receiving external sounds.
[0044] The sound acquisition device can be a microphone, also known as a "microphone" or "voice transducer," which can be used to receive the user's voice and convert the sound signal into an electrical signal. The terminal device 200 can be equipped with at least one microphone. In some embodiments, the terminal device 200 can be equipped with two microphones, which, in addition to acquiring sound signals, can also perform noise reduction. In other embodiments, the terminal device 200 can also be equipped with three, four, or more microphones, enabling sound signal acquisition, noise reduction, sound source identification, and directional recording functions, etc.
[0045] Furthermore, the microphone can be built into the terminal device 200, or it can be connected to the terminal device 200 via wired or wireless means. Of course, this embodiment does not limit the location of the microphone on the terminal device 200. Alternatively, the terminal device 200 may not include a microphone, meaning the microphone is not located within the terminal device 200. The terminal device 200 can connect an external microphone (also called a microphone) via an interface (such as a USB interface). This external microphone can be fixed to the terminal device 200 using an external fastener (such as a camera bracket with a clip).
[0046] The external device interface 240 may include, but is not limited to, one or more of the following: High Definition Multimedia Interface (HDMI), analog or high-definition component input interface (component), composite video input interface (CVBS), USB input interface (USB), RGB port, etc. It may also be a composite input / output interface formed by multiple interfaces mentioned above.
[0047] The controller 250 controls the operation of the terminal device and responds to user operations through various software control programs stored in the memory. The controller 250 controls the overall operation of the terminal device 200.
[0048] For example, the controller includes at least one of a central processing unit (CPU), an audio processor, a graphics processing unit (GPU), a RAM (Random Access Memory), a ROM (Read-Only Memory), a first to an nth interface for input / output, a communication bus, etc.
[0049] The audio output interface 270 is used to output audio signals to other devices for audio playback. In some embodiments, the terminal device 200 has a built-in speaker, and the audio output interface 270 can input audio signals to the speaker for audio playback. In other embodiments, the terminal device 200 can connect external audio devices such as amplifiers, speakers, and loudspeakers through the audio output interface 270, thereby inputting audio signals to these external audio devices for audio playback. For example, ... Figure 3 As shown, the terminal device 200 can be connected to an audio device via the audio output interface 270. Audio data can be sent to the audio device via the audio output interface 270 and then output and played through the audio device.
[0050] The audio output interface 270 may include, but is not limited to, one or more of the following: RCA port, clip-on port, SPDIF port, and headphone port. It may also be a composite output interface formed by multiple of the above interfaces.
[0051] To meet users' demand for high-quality music, music can be generated through the aforementioned terminal device 200 and played through the audio output interface 270. In some embodiments, music is composed of a combination of basic elements such as dynamics, tonality, duration, and timbre. Therefore, users can pre-set rules and templates for music generation, and the terminal device 200 generates music according to these rules and templates. For example, data parameters such as rhythm, mode, melody, and chords can be pre-set, allowing the terminal device 200 to generate music according to these data parameters. However, the above method requires users to manually set rules and templates, lacking adaptability and creativity, and making it difficult to generate diverse and rich music.
[0052] In some embodiments, the terminal device 200 can also generate music by training and learning music features based on a neural network algorithm. For example, music information data can be acquired as training data and input into a machine learning algorithm for training to learn music features, such as patterns and relationships between music elements, and then automatically derive new music. The above method can generate more diverse music, but requires a large amount of training data and time to achieve good results.
[0053] In some embodiments, the terminal device 200 can also optimize the search for music that meets the requirements by simulating the biological evolution process based on a genetic algorithm. The genetic algorithm population is initialized, and each individual in the population can be considered a solution to be optimized, i.e., a piece of music. The fitness function is used to evaluate the quality of each individual in the population, and evolutionary operations such as crossover, mutation, and selection are performed on the population to generate a new population. The new population replaces the original population in the next round of iterations until the stopping condition is met, at which point the optimal music is output. This method does not require pre-training, but the music generated by the genetic algorithm is of low quality and has a slow convergence speed.
[0054] To improve the quality and speed of music generation, some embodiments of this application also provide a music generation method applied to a terminal device 200. This method generates music based on a multi-population co-evolutionary approach, thereby improving the quality and speed of music generation. The terminal device 200, capable of applying the music generation method, includes an audio output interface 270 and a controller 250. The audio output interface 270 is configured to play music. The controller 250 is configured to execute the aforementioned music generation method. Figure 4 This is a flowchart illustrating the music generation method in an embodiment of this application, such as... Figure 4As shown, it specifically includes the following:
[0055] S100: Set the evaluation index function and constraints.
[0056] The music generation method provided in this application can simultaneously perform optimization searches based on multiple populations. Different populations can interact and cooperate through information sharing, exchange, or merging, thereby more comprehensively searching the solution space. Before performing multi-population co-evolution, it is necessary to determine the objective function and constraints for music generation, i.e., the problem to be solved or optimized based on the multi-population evolution algorithm. Therefore, users can pre-set evaluation index functions and constraints, enabling the terminal device 200 to iteratively search for target music based on the multi-population evolution algorithm according to the evaluation index functions and constraints.
[0057] The evaluation index function is used to judge the quality of individuals in a population. When setting the evaluation index function, it can be based on characteristics related to musical melody and rhythm. Specifically, in some embodiments, a music file can be obtained, and musical features can be extracted from the music file. These musical features include, but are not limited to, melody and rhythm features. A quality evaluation index is then generated based on these musical features.
[0058] Musical features may include the number of notes, note sequences, melody, etc., that make up the music. In some embodiments, quality assessment metrics may include the nine metrics shown in the table below. Each metric may be defined based on the English symbols shown in the table below, and each quality assessment metric may be associated with a musical feature to evaluate the quality of the music.
[0059] Quality assessment indicators describe ER The number of notes that are repeated the most times NOJ The number of notes that jump more than an octave MAR1 First-order autocorrelation of note sequences MAR2 Second-order autocorrelation of note sequences MAR3 Third-order autocorrelation of note sequences MUMax There is only one highest note in the melody. MUMin There is only one lowest note in the melody. Motif Number of notes that make up a motif PRMotif Number of notes in a repeating motif
[0060] To reduce the influence of different dimensions on quality assessment indicators and improve data processing speed, normalization can be performed on the quality assessment indicators to limit the indicator data to a preset data range, ensuring that different quality assessment indicators have the same measurement scale. It should be noted that the normalization method is not limited in this application; for example, linear normalization, zero-mean normalization, nonlinear normalization, batch normalization, and max-min normalization can be used. Taking max-min normalization as an example, the quality assessment indicators can be linearly transformed, and the transformed structure can be mapped to a preset data range (such as values between [0, 1]).
[0061] To meet users' needs for generating different types of music, the normalized quality assessment indicators can be weighted. Based on user needs, different weights can be assigned to different quality assessment indicators, thereby better reflecting the importance of each quality assessment indicator in the indicator system.
[0062] Constraints are the rules and constraints for music generation, that is, the restrictions and requirements imposed when generating music based on a multi-population evolutionary algorithm. Constraints can be set according to the basic elements that make up music, such as rhythm, melody, harmony, as well as dynamics, tempo, mode, form, and texture. In some embodiments, constraints may include note ranges and rhythmic ranges. The note range includes rests and the seven basic pitches: Do, Re, Mi, Fa, Sol, La, Si. The rhythmic range includes whole notes, half notes, quarter notes, ..., sixteenth notes, thirty-second notes, etc. The note data in the note range and the rhythmic data in the rhythmic range can be represented based on preset symbols. For example, the numbers 0, 1, 2, 3, 4, 5, 6, 7 represent rests, Do, Re, Mi, Fa, Sol, La, Si, respectively. The numbers 1, 2, 4, ..., 16, 32 represent whole notes, half notes, quarter notes, ..., sixteenth notes, thirty-second notes, respectively.
[0063] S200: Create the initial population.
[0064] Once the evaluation metrics and constraints for music generation are set, music can be generated based on a multi-population evolutionary algorithm. This involves creating an initial population, which includes multiple populations, and assigning different control parameters to each population. Optimization searches are then performed simultaneously across these multiple populations to obtain music generated through co-evolution. Each population is relatively independent, and information exchange between populations can be achieved by introducing the best individuals generated during the evolutionary process into other populations through a pre-defined migration operator.
[0065] In some embodiments, such as Figure 5 As shown, the initial population includes a first population and a second population, that is, the initial population is divided into two subgroups (the first population and the second population), the first population and the second population are iteratively evolved respectively, and the two subgroups can share information. Based on the first population and the second population, optimization search is performed simultaneously to generate the target music.
[0066] S300: Iteratively evolve the first population using the first algorithm, and iteratively evolve the second population using the second algorithm.
[0067] The first algorithm can be a particle swarm optimization (PSO) algorithm, and the second algorithm can be a genetic algorithm based on an elitist retention strategy. Both PSO and genetic algorithms based on elitist retention are iterative optimization algorithms. PSO has a higher running speed and fewer control parameters; therefore, iterating the first subgroup using PSO can improve the search speed. Iterating the second subgroup using genetic algorithms can improve stability. Furthermore, different subgroups can interact and cooperate through information sharing, exchange, or merging, allowing multi-subgroup evolutionary algorithms to search the solution space more comprehensively, improving the algorithm's search capability and global optimization performance.
[0068] Particle swarm optimization (PSO) searches for optimal solutions through cooperation and information sharing among individuals in a swarm. Each individual (particle) in the swarm has two attributes: position and velocity. The individual's position represents a candidate solution to the optimization problem, i.e., a piece of music generated in this embodiment. The individual's velocity represents its search direction and distance. Each individual in the search space is randomly assigned an initial position and initial velocity. Then, each individual's position is moved sequentially based on its velocity, the global optimal position in the search space, and its local optimal position. The position of each individual in the next generation is determined by its position in the current generation and its own velocity; velocity determines the direction and distance the individual moves in each iteration. As the algorithm iterates, all individuals will cluster around a single position, indicating that the optimal solution has been found.
[0069] To better understand the Particle Swarm Optimization (PSO) algorithm, let's take the example of a flock of birds searching for the largest food source. Within the search area, there are food sources of varying sizes, and the flock's task is to find the largest food source (the optimal solution). Throughout the search process, each bird transmits its position information to the others, allowing them to know the location of the food source. Through continuous movement and iteration, the entire flock eventually gathers around the largest food source, indicating that the optimal solution has been found.
[0070] In this embodiment, the quality of each individual's position within the search space can be determined based on the fitness function value of that individual's position in the problem to be solved or optimized. The fitness function value can be calculated based on the evaluation index function of music generation and the constraints. Each individual searches for the optimal solution independently in the search space, calculates its local optimal position based on the fitness function value, and shares this local optimal position with other individuals in the population. The best local optimal position among all individuals in the population is then taken as the global optimal position. All individuals in the population adjust their speed and position based on their current position, current velocity, local optimal position, and global optimal position.
[0071] like Figure 6The diagram illustrates the process of iteratively evolving the first swarm using the particle swarm optimization algorithm. The positions and velocities of individuals in the first swarm are initialized by assigning each individual a random initial position and velocity. Here, position represents a point in the search space of the first swarm, and velocity represents the individual's search direction and search distance.
[0072] After assigning an initial position and initial velocity to each individual, the fitness function value of the individual's current position can be calculated, and the local optimal position and the global optimal position can be updated based on the fitness function value. The fitness function value characterizes the quality of the individual's current position; the local optimal position is the position with the highest fitness function value, and the global optimal position is the position with the highest fitness function value in the first population.
[0073] For each individual, its current fitness function value can be compared with the fitness function value corresponding to its local optimum. If the fitness function value of the current position is greater than the fitness function value corresponding to the local optimum, then the current position is updated to the local optimum. If the fitness function value of the current position is less than or equal to the fitness function value corresponding to the local optimum, then the local optimum is not updated.
[0074] For the first type of population, we can traverse the local optimal positions of all individuals. If there is a local optimal position whose fitness function value is greater than the fitness function value corresponding to the global optimal position, then we update the local optimal position to the global optimal position.
[0075] The individual's position and velocity are updated. Specifically, the individual's position is updated based on its local optimum, global optimum, and current position; its velocity is updated based on its local optimum and current velocity. Each individual's position in the next generation is determined by its position and velocity in the current generation. During iterative movement, the individual's local optimum and its corresponding fitness function value, as well as the population's global optimum and its corresponding fitness function value, are recorded. The individual moves based on its local optimum, global optimum, current velocity, and current position, progressively searching for the global optimum until a preset stopping condition is met, at which point iterative evolution stops, and the global optimum of the first population is output.
[0076] In some embodiments, the stopping condition can be that when the number of iterations reaches an iteration threshold, the iterative evolution stops, and the global optimal position of the first swarm is output. For example, the user can preset the iteration threshold and store it in the terminal device 200. When iteratively evolving the first swarm using the particle swarm optimization algorithm, after initializing the initial position and initial velocity of the individuals in the first swarm, the fitness function value of the individual's current position is calculated. The local optimal position and the global optimal position are updated according to the fitness function value, that is, the position with the highest individual fitness function value is taken as the local optimal position (the individual's initial position is taken as the local optimal position in the first iteration). The local optimal positions of all individuals are traversed, and the local optimal position with the highest fitness function value is taken as the global optimal position. Then, the individual's position is updated according to the local optimal position, the global optimal position, and the individual's current position, and the individual's velocity is updated according to the local optimal position and the individual's current velocity, thus completing one iteration. The above iterative evolution process is repeated. When the number of iterations reaches the iteration threshold, the iterative evolution stops, and the global optimal position is output. For example, if the iteration threshold is 100, the global optimal position is output when the number of iterations reaches 100.
[0077] In some embodiments, the stopping condition can be that when the fitness function value is greater than the fitness threshold, the iterative evolution stops, and the global optimal position of the first population is output. That is, when iteratively evolving the first population using the particle swarm optimization algorithm, the fitness function value of the individual's current position is calculated. The local optimal position and the global optimal position are updated based on the fitness function value. The position with the highest fitness function value is taken as the local optimal position. All individuals' local optimal positions are traversed, and the local optimal position with the highest fitness function value is taken as the global optimal position. The fitness function value of the global optimal position is compared with the fitness threshold. If the fitness function value of the global optimal position is greater than the fitness threshold, the iterative evolution stops, and the global optimal position of the first population is output. If the fitness function value of the global optimal position is less than or equal to the fitness threshold, the individual's position and velocity are updated based on the local optimal position, the global optimal position, the individual's current position, and the individual's current velocity. The above iterative evolution process is repeated. In each iteration, the fitness function value of the global optimal position is compared with the fitness threshold until the fitness function value of the global optimal position is greater than the fitness threshold, at which point the iterative evolution stops, and the global optimal position is output.
[0078] Genetic algorithms search for optimal solutions by simulating the natural evolutionary process. They transform the problem to be solved or optimized into processes like crossover and mutation of chromosomes and genes in biological evolution, gradually approaching the optimal solution through continuous population evolution. The second population comprises multiple individuals (chromosomes), each representing a candidate solution to the optimization problem, i.e., a piece of music generated in this embodiment. Each individual includes multiple gene parameters, each representing a component or attribute of the candidate solution. Multiple individuals (chromosomes) constitute a population; that is, multiple solutions to an optimization problem constitute a population of solutions.
[0079] In this process, the quality of each individual within the search space can be determined based on its fitness function value within the problem to be solved or optimized. In this embodiment, the fitness function value can be calculated based on the evaluation index function and constraints of the music generation. Individuals with higher fitness function values correspond to better candidate solutions. Gene parameters for each individual are randomly generated to form an initial population. The initial population is iteratively evolved. In each iteration, individuals are selected based on their fitness function values, and crossover and mutation are performed on them using genetic operators to generate a new population of new individuals. It can be understood that each iterative evolution process is a process of gradually generating better solutions; through iterative evolution, the optimal individual is generated, i.e., the optimal solution is found.
[0080] like Figure 7 The diagram shows the process of iteratively evolving the second population using a genetic algorithm. Individuals in the second population are initialized, and each individual includes multiple gene parameters. The gene parameters of individuals in the second population are randomly generated.
[0081] After initializing individuals, their fitness function values can be calculated, and individuals can be selected based on these values. The fitness function value characterizes the quality of an individual. Individuals in the second population are selected using a selection operator; superior individuals are directly added to the next generation population, or new individuals are generated through crossover and mutation operations and then added to the next generation population. To improve evolutionary efficiency, individuals can be selected based on their fitness function values, choosing those with higher fitness function values.
[0082] A crossover operation is performed on selected individuals to generate new individuals. That is, based on the crossover operator, a crossover operation is performed on selected individuals to generate new individuals. The crossover operation involves exchanging gene parameters between two individuals to generate a new individual. There are various types of crossover operations, such as single-point crossover, two-point crossover, multi-point crossover, uniform crossover, or arithmetic crossover.
[0083] Mutation operations are performed on the genetic parameters of selected individuals to generate new genetic parameters. Specifically, mutation operations are applied to the newly generated individuals based on mutation operators, introducing new genetic parameters and thus increasing the diversity of the search space. The mutation operation replaces the genetic parameters at an individual's locus with other allele parameters at that locus, thereby generating new genetic parameters. Various mutation methods are available, such as basic position mutation, uniform mutation, boundary mutation, non-uniform mutation, or Gaussian approximation mutation.
[0084] The newly generated individuals are added to the second population to update it. This process of selection, crossover, and mutation, followed by the addition of new individuals to the second population, updates the population and completes one iteration of evolution. Simultaneously, some individuals with low fitness function values can be removed from the second population, while others with high fitness function values are retained. For example, a threshold can be set, comparing the fitness function value of each individual in the second population to the threshold, retaining individuals with fitness function values greater than the threshold, and removing individuals with fitness function values less than or equal to the threshold.
[0085] After the second population completes one iteration of evolution, all individuals in the second population can be traversed, and the individual with the highest fitness function value is selected as the optimal individual. This iterative evolution process is repeated, generating an optimal individual after each iteration, with the fitness function value of the optimal individual continuously increasing with the number of iterations. This continues until a preset stopping condition is met, at which point the iterative evolution stops, and the optimal individual of the second population is output.
[0086] The stopping condition can be set with reference to the stopping condition of the particle swarm optimization algorithm described above. When iteratively evolving the second population using a genetic algorithm, the gene parameters of individuals in the second population can be initialized, the fitness function value of the individuals can be calculated, individuals can be selected based on the fitness function value, crossover operations can be performed on the selected individuals based on the crossover operator to generate new individuals, and mutation operations can be performed on the newly generated individuals based on the mutation operator to introduce new gene parameters. The generated new individuals are then added to the second population, while some individuals with low fitness function values are deleted, and some individuals with high fitness function values are retained to update the second population, and the best individual in the second population (the individual with the highest fitness function value) is updated. The above iterative evolution process is repeated, and when the number of iterations reaches the iteration threshold, the iterative evolution stops, and the best individual in the second population is output.
[0087] A fitness threshold can also be preset. After each iteration, the fitness function value of the best individual is compared with the fitness threshold. If the fitness function value of the best individual is greater than the fitness threshold, the iteration stops and the best individual of the second population is output. If the fitness function value of the best individual is less than or equal to the fitness threshold, the iteration continues until an best individual with a fitness function value greater than the fitness threshold is generated.
[0088] In some embodiments, individuals can be selected using a roulette wheel selection method. This involves setting the selection probability of each individual, where the selection probability is the likelihood of an individual being selected, and the fitness function value is directly proportional to the selection probability. That is, the probability of an individual being selected is positively correlated with the fitness function value. A predetermined number of individuals are selected from the second population according to the selection probability. This method is similar to a roulette wheel lottery, where the wheel is divided into multiple unequal sector areas, and the pointer has a higher probability of landing on a larger sector. Similarly, the higher an individual's fitness function value, the higher its probability of being selected.
[0089] For example, after initializing the individuals in the second population, calculate the fitness function value of each individual, set the selection probability of the individuals based on the fitness function value, and select 7 individuals from the second population according to the selection probability. In this way, individuals with higher fitness function values can be selected for crossover and mutation operations. Alternatively, a roulette wheel selection algorithm can be used to select two individuals according to the selection probability, compare the fitness function values of the two individuals, and select the individual with the higher fitness function value. This process is repeated until 7 individuals have been selected.
[0090] To retain individuals with high fitness function values, individuals with high fitness function values can be selected from the second population and directly added to the next generation population. That is, in some embodiments, such as... Figure 8 As shown, the first individual can be selected, where the fitness function value is greater than a first threshold. This first individual is retained and added to the updated second population. Specifically, in each iteration of evolution, the fitness threshold of an individual is compared with the first threshold, selecting the first individual with a fitness threshold greater than the first threshold. Crossover and mutation operations are not performed on this first individual, while crossover and mutation operations are performed on the other selected individuals to generate new individuals, which are then added to the second population to update it. Alternatively, when selecting individuals, the individuals in the second population can be traversed, retaining the individual with the highest fitness function value; this is an elite retention strategy, replicating the best individual in the current population to the next generation.
[0091] For example, such as Figure 9As shown, when iteratively evolving the second population using a genetic algorithm, the gene parameters of individuals in the second population are initialized, the fitness function value of each individual is calculated, individuals are selected based on their fitness function values, and the first individual with the highest fitness function value is retained. Crossover is performed on the selected individuals using the crossover operator to generate new individuals, and mutation is performed on the newly generated individuals using the mutation operator to introduce new gene parameters. The newly generated individuals are added to the second population, and some individuals with low fitness function values are deleted, while some individuals with high fitness function values are retained. This iterative evolution process is repeated until the number of iterations reaches an iteration threshold, at which point the iterative evolution stops, and the individual with the highest fitness function value in the second population is output.
[0092] S400: Interval preset number of iterations, perform exchange operation on individuals in the first population and individuals in the second population.
[0093] Since the first and second groups are independent of each other, information sharing between the first and second groups is necessary. For example... Figure 5 As shown, migration conditions can be set. When these conditions are met, an exchange operation is performed between individuals in the first population and individuals in the second population, thereby exploring the solution space more comprehensively. The migration condition can be the exchange operation performed between the first and second populations at a preset number of iterations. For example, the preset number of iterations can be 4, with the exchange operation performed between individuals in the first and second populations every 4 iterations.
[0094] When performing a swap operation, individuals with lower fitness function values in the first population can be replaced by individuals with higher fitness function values in the second population, and vice versa. That is, in some embodiments, such as... Figure 10 As shown, a second individual can be selected from the first population, and a third individual can be selected from the second population. The second individual is defined as one with a fitness function value greater than a second threshold, and the third individual is defined as one with a fitness function value less than a third threshold. The second threshold is greater than the third threshold. In other words, the second individual with a higher fitness function value is selected from the first population, and the third individual with a lower fitness function value is selected from the second population. The third individual in the second population is then replaced with the second individual.
[0095] The above describes how individuals from the first population are introduced into the second population. Similarly, individuals with lower fitness function values can be selected from the first population, and individuals with higher fitness function values can be selected from the second population. Individuals with lower fitness function values in the first population can be replaced with individuals with higher fitness function values in the second population, thereby introducing individuals from the second population into the first population.
[0096] Alternatively, one could select the individual with the highest fitness function value from the first population, and the individual with the lowest fitness function value from the second population, then replace the individual with the highest fitness function value from the first population with the individual with the lowest fitness function value from the second population. Correspondingly, one could replace the individual with the lowest fitness function value from the first population with the individual with the highest fitness function value from the second population, thereby achieving information sharing between the first and second populations.
[0097] S500: Generate target music.
[0098] In this embodiment, different algorithms are used to iteratively evolve the first and second populations, and information can be shared between the populations. Through multi-population co-evolution, the target music is iteratively searched. Referring to the above embodiment of iterative evolution of the first and second populations, the target music is the individual output by the first and second populations after iterative evolution when a preset stopping condition is met.
[0099] The target music can be individuals whose fitness function value is greater than a preset fitness threshold when the number of iterations equals the iteration threshold. The fitness function value can be calculated based on the evaluation index function and constraints. The evaluation index function is the fitness function, which maps the characteristics of individuals in the population to a real value, i.e., the fitness function value. Furthermore, a penalty term can be constructed based on the constraints and applied to the fitness function. Based on the penalty function method, the fitness function value of individuals that violate the constraints can be reduced, thus obtaining the final fitness function value based on the evaluation index function and constraints.
[0100] By setting an iteration threshold in advance, the individuals output after each generation of evolution in each population are stored to form a candidate set. When the number of iterations in the first and second populations reaches the iteration threshold, the iteration evolution stops. Target individuals with fitness function values greater than the preset fitness threshold are selected from the candidate set, and target music is generated based on the target individuals.
[0101] Alternatively, an iteration threshold can be preset. When the number of iterations in the first and second populations reaches the iteration threshold, the iteration evolution stops, and the individuals output after the evolution of the first and second populations are obtained. The target music is then generated based on the individual with the highest fitness function value.
[0102] The target music can also be individuals whose fitness function value is greater than a preset fitness threshold. That is, when using different algorithms to iteratively evolve the first and second populations respectively, after each iteration, the individuals output by the first and second populations are obtained respectively. If there is an individual whose fitness function value is greater than the preset fitness threshold, the iterative evolution stops, and the target music is generated based on that individual.
[0103] In this embodiment, the population is divided into a first population and a second population. The first population is iteratively evolved using a particle swarm optimization algorithm to improve search speed. The second population is iteratively evolved using a genetic algorithm to improve algorithm stability. Furthermore, information sharing between different populations allows the multi-population evolutionary algorithm to search the solution space more comprehensively, thereby improving the quality and speed of music generation.
[0104] Based on the above music generation method, some embodiments of this application also provide a terminal device 200, including: an audio output interface 270 and a controller 250. The audio output interface 270 is configured to play music, and the controller 250 is configured to execute the following program steps:
[0105] S100: Set the evaluation index function and constraints.
[0106] S200: Create the initial population.
[0107] The initial population includes the first population and the second population.
[0108] S300: Iteratively evolve the first population using the first algorithm, and iteratively evolve the second population using the second algorithm.
[0109] S400: Interval preset number of iterations, perform exchange operation on individuals in the first population and individuals in the second population.
[0110] S500: Generate target music.
[0111] The target music is the individual whose fitness function value is greater than the preset fitness threshold when the number of iterations equals the iteration threshold. The fitness function value is calculated based on the evaluation index function and constraints.
[0112] As can be seen from the above technical solutions, the terminal device and music generation method provided in the above embodiments can set the evaluation index function and constraints for music generation, and create an initial population, wherein the initial population includes a first population and a second population. Then, a first algorithm is used to iteratively evolve the first population to iteratively search for the optimal individual in the first population, and a second algorithm is used to iteratively evolve the second population to iteratively search for the optimal individual in the second population. Furthermore, at preset iteration intervals, individuals in the first population and individuals in the second population are swapped. Finally, a target music is generated based on the results of the iterative evolution, wherein the target music is an individual whose fitness function value is greater than a preset fitness threshold when the number of iterations equals the iteration threshold, and the fitness function value is calculated based on the evaluation index function and constraints. The method uses a multi-population co-evolution approach to generate music, which can more comprehensively search the solution space, thereby improving the quality and speed of music generation.
[0113] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0114] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the described embodiments and various different variations of embodiments suitable for specific use considerations.
Claims
1. A terminal device, characterized by comprising: The method comprises: an audio output interface configured to play music; a controller configured to: set an evaluation index function and a constraint condition; create an initial population, the initial population comprising a first population and a second population; evolve the first population using a first algorithm and evolve the second population using a second algorithm; the first algorithm is a particle swarm algorithm and the second algorithm is a genetic algorithm based on an elite reservation strategy; perform a swap operation on individuals in the first population and individuals in the second population at intervals of a preset number of iterations; generate target music, the target music being an individual whose fitness function value is greater than a preset fitness threshold when the number of iterations is equal to an iteration threshold, the fitness function value being calculated according to the evaluation index function and the constraint condition; the controller performing the step of performing a swap operation on individuals in the first population and individuals in the second population is further configured to: select a second individual in the first population and a third individual in the second population, the second individual being an individual whose fitness function value is greater than a second threshold, and the third individual being an individual whose fitness function value is less than a third threshold, the second threshold being greater than the third threshold; replace the third individual in the second population with the second individual.
2. The terminal device according to claim 1, characterized by The controller performing the step of setting an evaluation index function is configured to: obtain a music file; extract music features from the music file, the music features comprising melody features and rhythm features; generate a quality evaluation index according to the music features; perform normalization processing on the quality evaluation index and perform weighting processing on the normalized quality evaluation index.
3. The terminal device of claim 1, wherein, The controller performing the step of evolving the first population using a first algorithm is configured to: initialize positions and velocities of individuals in the first population, the positions being used to represent points in a search space of the first population, and the velocities being used to represent search directions and search distances of the individuals; calculate a fitness function value of a current position of the individual; update a local optimal position and a global optimal position according to the fitness function value, the local optimal position being a position with the highest fitness function value of the individual, and the global optimal position being a position with the highest fitness function value of the first population; update the position of the individual according to the local optimal position, the global optimal position and the current position of the individual, and update the velocity of the individual according to the local optimal position and the current velocity of the individual; output the global optimal position of the first population when the number of iterations reaches an iteration threshold.
4. The terminal device according to claim 1, characterized by The controller performing the step of evolving the second population using a second algorithm is configured to: initialize individuals of the second population, the individuals comprising a plurality of gene parameters; calculate a fitness function value of the individual; select an individual according to the fitness function value; perform a crossover operation on the selected individual to generate a new individual; perform a mutation operation on a gene parameter of the selected individual to generate a new gene parameter; add the generated new individual to the second population to update the second population; When the number of iterations reaches an iteration threshold, output an individual whose fitness function value is greater than a preset fitness threshold.
5. The terminal device according to claim 4, characterized by The controller, which performs the step of selecting an individual according to the fitness function value, is further configured to: set a selection probability of the individual, the fitness function value being in direct proportion to the selection probability; select a preset number of individuals in the second population according to the selection probability.
6. The terminal device according to claim 4, characterized by The controller, which performs the step of selecting an individual according to the fitness function value, is further configured to: screen a first individual, the first individual being an individual whose fitness function value is greater than a first threshold value; retain the first individual and add the first individual to an updated second population.
7. The terminal device of claim 1, wherein, The controller is further configured to: respectively obtain individuals output by the first population and the second population after performing iterative evolution; if there is an individual whose fitness function value is greater than a preset fitness threshold, stop iterative evolution and generate target music based on the individual.
8. A music generation method characterized by, The method comprises: setting an evaluation index function and a constraint condition; creating an initial population, the initial population comprising a first population and a second population; iteratively evolving the first population using a first algorithm and iteratively evolving the second population using a second algorithm; the first algorithm being a particle swarm algorithm and the second algorithm being a genetic algorithm based on an elite reservation strategy; performing a swap operation on individuals in the first population and individuals in the second population at intervals of a preset number of iterations; generating target music, the target music being an individual whose fitness function value is greater than a preset fitness threshold when the number of iterations equals an iteration threshold, the fitness function value being calculated according to the evaluation index function and the constraint condition; performing a swap operation on individuals in the first population and individuals in the second population further comprises: screening a second individual in the first population and a third individual in the second population, the second individual being an individual whose fitness function value is greater than a second threshold value, and the third individual being an individual whose fitness function value is less than a third threshold value, the second threshold value being greater than the third threshold value; replacing the third individual in the second population with the second individual.
Citation Information
Patent Citations
A mixed algorithm-based computer-aided composition method for popular tunes in regions south of the Yangtze River
CN105374347A
D2D communication resource optimization method based on multi-population genetic algorithm
CN106792451A
Industrial control intrusion detection classifier parameter selection method based on multi-population genetic algorithm
CN113128655A