Dynamic music synthesis method and system based on sleep stage
Through multi-scale space-time attention-enhanced meta-learning reinforcement learning framework and conditional generation adversarial network, combined with EEG and motion sensor data, the reward sparseness and state space complexity of sleep assisted music systems in the existing technology are solved. An efficient and personalized sleep assisted music system has been realized, improving sleep quality and user experience.
Patent Information
- Application Number
- CN202411123694.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2025-01-10
AI Technical Summary
The existing technology has reward sparsity, state space complexity, insufficient adaptability to individual differences, insufficient long-term dependency capture capabilities, limited music generation quality and lack of intelligent wake-up mechanism in the sleep-assisted music system, resulting in the inability to provide truly personalized and efficient sleep assistive services.
Adopt multi-scale space-time attention-enhanced meta-learning reinforcement learning framework, combining lightweight EEG and motion sensor data, identify sleep stages through an improved two-way LSTM network, and use conditional generation adversarial network to generate music to predict the optimal wake-up time Window, adjust music parameters to promote natural wake-up and continuously optimize the system through incremental learning.
It has realized high-precision sleep stage recognition, adaptive music parameter optimization, personalized music generation, intelligent wake-up planning and continuous optimization, significantly improving sleep quality and user experience, and providing long-term and effective sleep assistance services.
Smart Images

Figure CN119280612A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of dynamic music synthesis methods, and more specifically, to a dynamic music synthesis method based on sleep stages and a system thereof. Background Art
[0002] Sleep quality is essential to human physical and mental health. In recent years, with the accelerated pace of life and increased stress, sleep disorders have become a common health problem. In order to improve sleep quality, people have tried various methods, among which music therapy has attracted widespread attention due to its non-invasive and convenient characteristics.
[0003] The current status of the existing technology mainly includes the following aspects:
[0004] 1. Fixed music playback system: This is the earliest and simplest sleep music assistance method. The system plays fixed light music or white noise at a preset time to help users fall asleep. However, this method cannot adjust the music according to the user's actual sleep condition, and the effect is limited.
[0005] 2. Simple sleep stage recognition system: With the development of wearable devices, some systems have begun to try to recognize the user's sleep stage and switch preset music according to the sleep stage. This method is an improvement over fixed music playback, but the music switching is often not smooth enough and may affect sleep quality.
[0006] 3. Dynamic music generation system based on traditional machine learning: This type of system uses traditional machine learning algorithms (such as support vector machines, decision trees, etc.) to analyze sleep data and generate music. Although it can achieve dynamic adjustment to a certain extent, it is not adaptable enough to complex and nonlinear sleep patterns.
[0007] 4. Music synthesis system using simple reinforcement learning: Some recent studies have begun to introduce reinforcement learning technology, trying to optimize music parameters by interacting with the environment (user's sleep state). This method has improved in adaptability, but there are still some problems.
[0008] The main problems of the existing technology:
[0009] Take the music synthesis system using simple reinforcement learning as an example. It has the following key problems:
[0010] 1. Reward sparsity: Feedback on sleep quality is usually obtained only after the entire sleep cycle is over, which makes it difficult for the reinforcement learning algorithm to adjust its strategy in time, affecting learning efficiency.
[0011] 2. State space complexity: Sleep data contains a large number of high-dimensional, time-varying features. Simple reinforcement learning algorithms are difficult to effectively handle such a complex state space.
[0012] 3. Insufficient adaptability to individual differences: Everyone’s sleep patterns and music preferences are different, and simple reinforcement learning algorithms are difficult to quickly adapt to such individual differences.
[0013] 4. Insufficient ability to capture long-term dependencies: Sleep is a long process, and simple reinforcement learning algorithms are difficult to capture the long-term dependencies between different stages of sleep.
[0014] 5. Limited quality of music generation: Existing systems usually use preset music clips for combination, which makes it difficult to generate truly personalized and smoothly transitioned music.
[0015] 6. Lack of intelligent wake-up mechanism: Most systems only focus on the process of falling asleep and sleeping, ignoring the importance of the wake-up stage, which may cause users to be awakened in deep sleep, affecting sleep quality.
[0016] These problems severely limit the effectiveness of existing technologies, making it difficult to provide users with truly personalized and efficient sleep assistance services. Therefore, developing a new method that can overcome these problems has important practical significance and market value. Summary of the invention
[0017] The present invention aims at the above-mentioned problems and proposes a dynamic music synthesis method based on sleep stages and a system thereof.
[0018] The present invention provides a dynamic music synthesis method based on sleep stages, comprising the following steps: acquiring user sleep data; identifying the user's sleep stage based on the user sleep data; dynamically optimizing music parameters according to the sleep stage using a multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework; generating music based on the optimized music parameters and achieving smooth transition; during the music playback process, continuously monitoring the user's sleep state and predicting the optimal wake-up time window; when the optimal wake-up time window is detected, adjusting the music parameters to promote the user to wake up naturally; after the user wakes up, collecting user feedback; updating the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework based on the user feedback; and repeating the above steps to continuously optimize the user's sleep experience.
[0019] Specifically, the obtaining of user sleep data includes: collecting EEG data and motion data using a lightweight EEG device and a motion sensor;
[0020] The EEG data and the motion data are subjected to denoising processing to obtain denoised data, wherein the denoising processing adopts a wavelet threshold denoising algorithm, and the formula is:
[0021] ψ j,k (t) = 2 (j / 2) ψ(2 j tk)
[0022] Where ψ is a wavelet function, j is a scale, k is a translation parameter, and t is a time variable; the denoised data is normalized to obtain normalized data, wherein the normalization process adopts an improved Z-score normalization, and the formula is:
[0023]
[0024] Where x is the original data, μ is the mean, σ is the standard deviation, and ∈ is a small positive number (1e-8); feature extraction is performed on the normalized data to obtain a feature vector; wherein the feature vector is used as input for subsequent steps.
[0025] Specifically, the method for identifying the user's sleep stage adopts an improved bidirectional LSTM network, and its algorithm steps include:
[0026] 1) Initialize network parameters W f ,W b ,W o ,b f ,b b ,b o ;
[0027] (2) For the input sequence X = [x1, x2, ..., x T ], calculate the forward hidden state:
[0028] (3) Calculate the backward hidden state:
[0029] (4) Calculate the output layer:
[0030] Among them, σ is the activation function, x t is the input feature vector, and are the forward and backward hidden states, y t Output sleep stage probability distribution.
[0031] Specifically, the music is generated based on the optimized music parameters and a smooth transition is achieved by using an improved conditional generative adversarial network (C-GAN), and the algorithm steps include:
[0032] (1) Initialize the parameters of the generator G and the discriminator D;
[0033] (2) Generator G generates music clips:
[0034] G(z,c)=tanh(W g [z,c]+b g)
[0035] (3) The discriminator D distinguishes real music from generated music: D(x,c) = σ(W d [x,c]+b d )
[0036] (4) Optimize the objective function:
[0037] min G max D V(D,G)=E x [logD(x|c)]+E z [log(1-D(G(z|c)))]+λL smooth
[0038] Among them, z is random noise, c is the conditional vector (including music parameters and sleep stage information), x is the real music sample, and W g ,W d ,b g ,b d is a learnable parameter, λ is the weight of the smooth loss term, L smooth is a smooth loss function.
[0039] Specifically, the prediction of the optimal wake-up time window adopts a fuzzy time series prediction model, and its algorithm steps include:
[0040] (1) Define fuzzy sets:
[0041]
[0042] (2) Establish fuzzy logic relationship: R i =A i →A i+1 (3) Predict the state at the next moment:
[0043] F(t+1)=A i R i
[0044] Among them, A i represents a fuzzy set, is the membership function, u j is an element in the domain, R i is the fuzzy logic relationship matrix, and F(t+1) is the prediction result.
[0045] Specifically, the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework is updated based on the user feedback using an incremental learning algorithm, and its update formula is:
[0046]
[0047] Among them, θ is the model parameter, η is the learning rate, and D n ew is the newly collected data, L is the loss function, represents the gradient with respect to θ.
[0048] Specifically, the multi-scale spatiotemporal attention-enhanced meta-learning reinforcement learning framework includes: a quantum-inspired attention mechanism; a meta-learning algorithm based on fractal geometry; a hierarchical progressive strategy optimization based on chaos theory; and an adaptive reward shaping mechanism based on information entropy.
[0049] Specifically, the algorithm steps of the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework include:
[0050] (1) Constructing quantum state representation based on the quantum-inspired attention mechanism Among them, |t i >Quantum state representing time characteristics, |s j > quantum state representing spatial characteristics, α ij is the complex amplitude;
[0051] (2) Define the quantum evolution operator U and calculate the attention weight:
[0052] A=|<ψ|U|ψ>| 2
[0053] Among them, U is a unitary matrix, representing the evolution of the quantum system;
[0054] (3) Calculate the fractal dimension based on the meta-learning algorithm of fractal geometry
[0055]
[0056] Where N is the number of hyperspheres required to cover the set, r is the radius of the hypersphere,
[0057] (4) Define the meta-learning objective function:
[0058]
[0059] Among them, w i is the task weight, D i is the fractal dimension of the task, L i is the task loss function, θ is the model parameter;
[0060] (5) Based on the hierarchical progressive strategy optimization of the chaos theory, the chaotic sequence is calculated:
[0061] x n+1 = r·x n ·(1-x n )
[0062] Among them, r is the control parameter, x n ∈[0,1];
[0063] (6) Update global and local strategies:
[0064]
[0065]
[0066] Among them, α and β are learning rates, J(θ) and J(φ) are the objective functions of the global and local strategies respectively, and C(x n ) is the chaos metric function;
[0067] (7) Based on the adaptive reward shaping mechanism of the information entropy, the information entropy of the state is calculated:
[0068]
[0069] Where p(x) is the probability distribution of state x;
[0070] (8) Calculate adaptive rewards:
[0071]
[0072] w1=σ(H(s t )-H(s t-1 ))
[0073] w2=1-w1
[0074] Among them, r immediate For immediate reward, r l ong_term is the long-term reward, H(s t ) and H(s t-1 ) are the information entropy of the current state and the previous state respectively;
[0075] 9) Optimizing music parameters based on the attention weights, the meta-learning objective function, the updated strategy, and the adaptive reward.
[0076] Specifically, the optimization process of the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework further includes:
[0077] (1) Initialize model parameters θ and φ;
[0078] (2) For each time step t:
[0079] a) Get the current status s t ;
[0080] b) Use the quantum attention mechanism to calculate the attention weight A t ;
[0081] c) Calculate the fractal dimension D of the current task based on fractal geometry t ;
[0082] d) Generate x using chaos map n sequence;
[0083] e) Calculate the global action a global =π global (s t ) and local action a local =π local (s t );
[0084] f) Execute action a t =w g ·a global +(1-w g )·a local , where w g is the global action weight,
[0085] ()Observe the next state s t +1 and reward r t ;
[0086] h) Calculate the adaptive reward R t ;
[0087] i) Update the experience replay buffer D;
[0088] (3) Sample small batches of data from D for training:
[0089] a) Calculate the target Q value: y i =R i +γ·max a Q(s i+1 ,a;θ′)
[0090] b) Update Q network parameters:
[0091] c) Update the target network parameters: θ′=τ·θ+(1-τ)·θ′(4) Update the meta-learning parameters:
[0092]
[0093] Among them, γ is the discount factor, η is the learning rate, τ is the target network soft update parameter, η meta is the meta-learning rate.
[0094] A dynamic music synthesis system based on sleep stages, comprising:
[0095] A data acquisition module for acquiring user sleep data; a sleep stage recognition module connected to the data acquisition module and used to recognize the user's sleep stage based on the user's sleep data; a multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module connected to the sleep stage recognition module and used to dynamically optimize music parameters according to the sleep stage; a music generation module connected to the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module and used to generate music based on the optimized music parameters and achieve smooth transition; a wake-up planning module connected to the music generation module and the data acquisition module and used to continuously monitor the user's sleep state during music playback and predict the optimal wake-up time window ; A music control module connected to the wake-up planning module and the music generation module, used to adjust the music parameters when the optimal wake-up time window is detected to promote the user to wake up naturally; a feedback collection module used to collect user feedback after the user wakes up; a model updating module connected to the feedback collection module and the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module, used to update the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module based on the user feedback; wherein, the system continuously optimizes the user's sleep experience by cyclically executing the functions of the above modules, and the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module adopts the described method to optimize music parameters.
[0096] The beneficial effects of the present invention are mainly reflected in the following aspects:
[0097] 1. High-precision sleep stage recognition: By using lightweight EEG and motion sensors combined with an improved bidirectional LSTM network, the present invention can accurately identify the user's sleep stage, providing a reliable basis for subsequent music parameter optimization.
[0098] 2. Adaptive music parameter optimization: The multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework (MSAE-MRLF) can effectively handle complex state spaces, overcome the problem of reward sparsity, quickly adapt to individual differences, and significantly improve the effect of music parameter optimization.
[0099] 3. Personalized music generation: The improved conditional generative adversarial network (C-GAN) can generate high-quality, personalized music in real time based on the optimized music parameters, and achieve smooth transition, avoiding the interference of music switching on sleep.
[0100] 4. Intelligent wake-up planning: Through the fuzzy time series prediction model, the present invention can predict the optimal wake-up time window, wake up the user at the appropriate light sleep stage, and improve the comfort and mental state after getting up.
[0101] 5. Continuous optimization capability: By collecting user feedback and updating the MSAE-MRLF framework, the present invention can continuously adapt to changes in users' sleep patterns and provide long-term and effective sleep assistance services.
[0102] 6. Comprehensive improvement in sleep quality: As shown in the results of the examples, the present invention has achieved remarkable results in shortening the time to fall asleep, improving sleep efficiency, increasing the proportion of deep sleep, reducing the number of awakenings at night, etc., and has comprehensively improved the sleep quality of users.
[0103] 7. Excellent user experience: Highly personalized music synthesis and intelligent wake-up mechanism greatly enhance the user experience and help cultivate good sleeping habits.
[0104] 8. Non-invasive and convenient: The present invention uses lightweight sensors and intelligent algorithms, which does not require users to perform complex operations, ensuring accuracy without affecting normal sleep.
[0105] In summary, the present invention overcomes many limitations of the prior art and provides an efficient, personalized, and sustainably optimized sleep assistance solution, which is expected to play an important role in improving the public's sleep health and quality of life. BRIEF DESCRIPTION OF THE DRAWINGS
[0106] Figure 1 It is the overall logic block diagram of the system of the present invention.
[0107] Figure 2 This is the core algorithm logic block diagram of the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework of the present invention.
[0108] Figure 3 This is a logic block diagram of the sleep stage identification module of the present invention.
[0109] Figure 4 This is a logic block diagram of the music generation module of the present invention.
[0110] Figure 5 This is a logic block diagram of the wake-up planning module of the present invention.
[0111] Figure 6 It is a system logic block diagram of the present invention.
[0112] Figure 7 It is a multi-dimensional radar chart of the performance of the present invention and comparative examples 1-3.
[0113] Figure 8 It is a curve diagram of dynamic music parameter adjustment in sleep stages of the present invention and comparative examples 1-3. DETAILED DESCRIPTION
[0114] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the specific implementation methods, structures, features and effects thereof are described in detail below in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0115] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0116] The present invention is further described in detail below in conjunction with specific embodiments. In a typical application scenario of the present invention, user Xiao Zhang is often troubled by insomnia. He decides to try to use the dynamic music synthesis system based on sleep stages of the present invention to improve his sleep quality. The following describes in detail the entire process of Xiao Zhang using the system and how the system dynamically adjusts the music according to his sleep condition.
[0117] Please refer to Figure 1-8 The present invention discloses a dynamic music synthesis method based on sleep stages, comprising the following steps:
[0118] 1. Obtain user sleep data. When Xiao Zhang is ready to go to bed, he wears the system's lightweight EEG device (model: NeuroSkyMindWaveMobile2) and motion sensor (model: BoschBMI160). These devices will collect Xiao Zhang's EEG data and motion data in real time. The EEG data is collected at a frequency of 512Hz, and the motion data is collected at a frequency of 100Hz. The data acquisition module first preprocesses the collected raw data, including noise reduction, normalization, and feature extraction.
[0119] 1.1 Noise reduction processing, the system uses the wavelet threshold denoising algorithm to reduce the noise of the original data. The formula is:
[0120] ψ j,k (t) = 2 j / 2 ·ψ(2 j tk
[0121] ψ is the wavelet function. The system uses Daubechies wavelet (DB4) as the basic wavelet function. j is the scale parameter, which controls the expansion and contraction of the wavelet. In this system, the value range of j is 1 to 5 to cover noise of different frequencies. k is the translation parameter, which is used to move the wavelet on the time axis. The value range of k is from 0 to the signal length. t is the time variable.
[0122] In this formula: The system removes noise by adjusting the threshold, and the threshold is selected using the general threshold method:
[0123]
[0124] Where σ is the noise standard deviation and N is the signal length.
[0125] 1.2 Normalization After noise reduction, the system uses the improved Z-score normalization method to normalize the data. The formula is:
[0126]
[0127] Where: x is the original data point; μ is the mean of the data; σ is the standard deviation of the data; ε is a small positive number (1e-8) to prevent the denominator from being zero.
[0128] 1.3 Feature Extraction,The system uses nonlinear principal component analysis (NLPCA) for feature extraction.,NLPCA is implemented through an autoencoder, and its structure includes an encoder and a decoder.,The encoder maps the input data to a low-dimensional feature space, and the decoder reconstructs the low-dimensional features into the original data.
[0129] The system uses a three-layer autoencoder structure: input layer → hidden layer (64 neurons) → feature layer (16 neurons) → hidden layer (64 neurons) → output layer. The activation function is ReLU, the optimizer is Adam, and the learning rate is set to 0.001.
[0130] Through this series of preprocessing, the system obtains sleep data with noise reduction, normalization and key features extracted, laying the foundation for subsequent sleep stage identification.
[0131] 2. Identify the user's sleep stage Based on the preprocessed sleep data, the system uses an improved bidirectional long short-term memory network (Bi-LSTM) to identify Xiao Zhang's sleep stage. This network can capture long-term dependencies in time series data and is particularly suitable for processing sleep, a physiological process that is cyclical and continuous. The specific algorithm steps are as follows:
[0132] (1) Initialize network parameters W f ,W b ,W o ,b f ,b b ,b o .
[0133] W f ,W b, W o is the weight matrix, which is initialized using the Xavier initialization method. f′ ,b b′ ,b ois the bias vector, initialized to zero vector.
[0134] (2) For the input sequence X = [x1, x2, ..., x T ], calculate the forward hidden state: h f,t =σ(W f ·[h f,(t-1) ,x t ]+b f ),t=1,2,…,T
[0135] (3) Calculate the backward hidden state: h b,t =σ(W b ·[h b,(t+1) ,x t ]+b b ),t=T,T-1,…,1
[0136] (4) Calculate the output layer: y t =softmax(W o ·[h f,t ,h b,t ]+b o ),t=1,2,…,T
[0137] In these formulas: σ is the activation function, and the system uses LeakyRelU, which is defined as f(x) = max(0.01x, x). t is the input feature vector at time t, with a dimension of 16 (determined by the feature extraction step). f,t and h b,t are the forward and backward hidden states at time t, respectively, and the dimension is set to 64. t is the output at time t, which represents the probability distribution of each sleep stage. Sleep stages are divided into 5 categories: awake, N1, N2, N3 and REM. The network training uses the cross entropy loss function and Adam optimizer, with the learning rate set to 0.0001, batch size to 32, and the number of training rounds to 100. Through this improved Bi-LSTM network, the system can accurately identify Xiao Zhang's current sleep stage, providing an important basis for the subsequent optimization of music parameters.
[0138] The network training uses the cross entropy loss function and Adam optimizer, with the learning rate set to 0.0001, the batch size to 32, and the number of training rounds to 100.
[0139] Through this improved Bi-LSTM network, the system can accurately identify Xiao Zhang's current sleep stage, providing an important basis for subsequent music parameter optimization.
[0140] 3. Dynamically optimize music parameters. Based on the identified sleep stages, the system uses the Multi-Scale Spatiotemporal Attention Enhanced Meta-Learning Reinforcement Learning Framework (MSAE-MRLF) to dynamically optimize music parameters. Figure 2 , this innovative framework consists of four core components:
[0141] 3.1 Quantum-inspired attention mechanism, which draws on concepts from quantum mechanics to capture the complex correlations between multi-scale spatiotemporal features. The algorithm steps are as follows:
[0142] (1) Constructing quantum state representation: Among them, |t i >Quantum state representing time characteristics, |s j >Represents the quantum state of spatial characteristics. α ij is a complex amplitude, satisfying ∑ i,j |α ij | 2 =1.
[0143] (2) Definition of quantum evolution operator UU is a unitary matrix that represents the evolution of a quantum system. In this system, U is implemented by parameterized quantum circuits, including a single-qubit rotation gate and a two-qubit CNOT gate.
[0144] (3) Calculate the attention weight: A = |<ψ|U|ψ>| 2 This step calculates the overlap between the evolved quantum state and the initial state, and the obtained A is the attention weight. In practical applications, the system maps the temporal and spatial features of sleep data to 8 quantum bits to construct a 256-dimensional Hilbert space. The depth of the quantum circuit is set to 4 to balance the expressive power and computational complexity.
[0145] 3.2 Meta-learning algorithm based on fractal geometry. This algorithm uses the self-similarity principle of fractal geometry to capture learning patterns at different scales. The steps are as follows:
[0146] (1) Calculate the fractal dimension: D = log(N) / log(1 / r), where N is the number of hyperspheres required to cover the set and r is the radius of the hypersphere. The system estimates the fractal dimension using the box counting method, dividing the feature space into grids of different scales.
[0147] (2) Define the meta-learning objective function: L(θ) = ∑ i w i ·D i ·L i (f θ )
[0148] Among them, w i is the task weight, D iis the fractal dimension of the task, L i is the task loss function, θ is the model parameter
[0149] (3) Optimize the model parameters θ to minimize L(θ). The system uses the Adam optimizer, the learning rate is set to 0.001, and the number of training rounds is 50.
[0150] This algorithm can adaptively adjust the importance of different sleep stages and individual differences, improving the generalization ability of the model.
[0151] 3.3 Hierarchical progressive strategy optimization based on chaos theory. This component introduces chaos theory to increase the diversity and adaptability of strategy search. The steps are as follows:
[0152] (1) Initialize the chaotic map parameter r and the initial value x0. The system uses Logistic mapping, and the value range of r is [3.57, 4] to ensure that the system is in a chaotic state. x0 is randomly initialized between [0, 1].
[0153] (2) Calculate the chaotic sequence: x n +1=r·x n ·(1-x n )This sequence is used for subsequent strategy updates.
[0154] (3) Update the global policy:
[0155] (4) Update local strategy:
[0156] Where: α and β are learning rates, with an initial value of 0.01 and are dynamically adjusted during training. J(θ) and J(φ) are the objective functions of the global and local strategies, respectively. C(x n ) is the chaos metric function, defined as C(x n )=4x n (1-x n ). This strategy optimization method can strike a balance between global exploration and local development and adapt to the needs of different sleep stages.
[0157] 3.4 Adaptive reward shaping mechanism based on information entropy, this mechanism dynamically adjusts the weights of immediate rewards and long-term rewards to solve the problem of reward sparsity. The steps are as follows:
[0158] (1) Calculate the information entropy of the state: H(X) = -∑ x p(x)·log(p(x))where p(x) is the probability distribution of state x, obtained through statistics of historical data.
[0159] (2) Calculate the reward: R t =w1·rimmediate +w2·r long_term
[0160] w1=sigmoid(H(s t )-H(s t-1 ))w2=1-w1
[0161] Where: r immediate It is an instant reward, calculated based on current sleep quality indicators (such as brain wave stability). long_term is a long-term reward calculated based on the sleep quality score throughout the night. t ) and H(s t-1 ) are the information entropy of the current state and the previous state respectively.
[0162] In this way, the system can dynamically adjust the reward weight according to the changes in sleep state and improve learning efficiency. Based on the above four components, the MSAE-MRLF framework can generate optimal music parameters for Xiao Zhang's different sleep stages. For example, in the stage of falling asleep, the system may choose a lower volume and a slow rhythm; while in the deep sleep stage, it may choose more soothing music elements.
[0163] 4. Generate music and achieve smooth transition Based on the optimized music parameters, the system uses an improved conditional generative adversarial network (C-GAN) to synthesize music clips in real time and achieve smooth transition. The specific algorithm steps are as follows:
[0164] (1) Initialize the parameters of the generator G and the discriminator D. Both the generator and the discriminator adopt a deep convolutional neural network structure, and the He initialization method is used for initialization.
[0165] (2) Generator G generates a music clip: G(z,c) = tanh(W g ·[z,c]+b g )Where z is a 100-dimensional random noise vector that follows a standard normal distribution. c is a conditional vector containing music parameters (such as pitch, rhythm, volume, etc.) and sleep stage information, with a dimension of 20. g and b g are learnable parameters.
[0166] (3) Discriminator D distinguishes real music from generated music: D(x,c) = sigmoid(W d ·[x,c]+b d ) where x is a music sample (real or generated) and c is a conditional vector. d and b d are learnable parameters.
[0167] (4) Optimize the objective function:
[0168] min G max D V(D,G)=E x [logD(x|c)]+E z [log(1-D(G(z|c)))]+λ·L smooth
[0169] Among them, E x represents the expectation of the real sample, E z represents the expectation of random noise. L is the weight of the smoothing loss term, which is initially set to 0.1. smooth is a smooth loss function used to ensure the continuity of music transitions. It is defined as:
[0170]
[0171] Where t represents the time step, z t and c t are the random noise and condition vector at time t respectively. The system uses the Adam optimizer to train C-GAN, with the learning rate set to 0.0002, β1=0.5, β2=0.999. Each mini-batch contains 32 samples, and the training lasts for 100 epochs.
[0172] In this way, the system is able to generate unique and smooth music clips based on Xiao Zhang's current sleep stage and the optimized music parameters. For example, when Xiao Zhang transitions from light sleep to deep sleep, the music will gradually become more soothing and calming, but this change is gradual and will not cause abruptness and affect sleep quality.
[0173] 5. Predict the best wake-up time window In order to ensure that Xiao Zhang wakes up at the best time, the system uses a fuzzy time series prediction model to predict the best wake-up time window. The specific algorithm steps are as follows:
[0174] (1) Define fuzzy sets: Among them, u j are elements in the domain (such as different sleep stages or time points), is the membership function. The system divides sleep quality into five fuzzy sets: very poor, poor, average, good, and very good.
[0175] (2) Establish fuzzy logic relationship: R i =A i →A i+1 This step establishes the fuzzy relationship between adjacent time points. For example, if the current sleep quality is "good", the next time point may be "very good" or "average".
[0176] (3) Predict the state at the next moment: F(t+1) = Ai *R i Among them, * indicates fuzzy compound operation. The system uses the max-min compound method for prediction.
[0177] To improve prediction accuracy, the system also considers the following factors:
[0178] Sleep cycle: Usually a complete sleep cycle is about 90 minutes.
[0179] Personal habits: By analyzing Xiao Zhang’s historical data, we can understand his optimal sleep duration.
[0180] External factors: such as alarm settings, sunrise time, etc.
[0181] The system incorporates these factors into fuzzy rules, such as: "If you are currently in a light sleep stage and there are 20-30 minutes left before your alarm is set, then there is a high probability that this time period is the best wake-up window."
[0182] Using this method, the system is able to predict the best wake-up time window for Xiao Zhang, which is usually the light sleep stage after a complete sleep cycle.
[0183] 6. End music playback within the optimal wake-up time window. Once the system determines the optimal wake-up time window, it will begin to prepare to end music playback. This process is gradual to ensure that Xiao Zhang can wake up naturally and comfortably. The specific steps are as follows:
[0184] (1) 5-10 minutes before the predicted optimal wake-up time window begins, the system begins to adjust the music parameters.
[0185] (2) Gradually increase the tempo and volume of the music, but keep the amplitude within a range that will not suddenly wake Xiao Zhang up.
[0186] (3) Introduce some light but not stimulating music elements, such as birdsong or soft piano music
[0187] (4) At the optimal wake-up time, the music reaches the preset "wake-up mode" and then slowly fades out.
[0188] This gradual ending of the music can help Xiao Zhang wake up naturally, reduce sleep inertia, and make him feel energetic in the new day.
[0189] 7. Collect user feedback. In order to continuously improve system performance, after Xiao Zhang wakes up, the system will collect his feedback. This includes:
[0190] (1) Subjective sleep quality rating: Using a scale of 1-10, ask Xiao Zhang to rate his sleep quality.
[0191] (2) Objective sleep indicators: including total sleep time, sleep efficiency, and the proportion of each sleep stage.
[0192] (3) Music experience feedback: Ask Xiao Zhang how he feels about the music, such as whether it helps him fall asleep, whether he feels uncomfortable, etc.
[0193] (4) Wake-up experience feedback: Understand how Xiao Zhang feels when he wakes up and whether he feels natural and comfortable.
[0194] The system collects this feedback through a user-friendly interface (such as a mobile application), ensuring that it does not impose additional burden on Xiao Zhang.
[0195] 8. Update the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework. Based on the collected user feedback, the system uses an incremental learning algorithm to update the MSAE-MRLF framework. The update formula is:
[0197] Where: θ is the model parameter, η is the learning rate, the initial value is set to 0.01, but it will be dynamically adjusted according to the update effect, D new is the newly collected data, including sleep data and user feedback. L is the loss function, which takes into account both prediction accuracy and user satisfaction. represents the gradient with respect to θ.
[0198] The specific update process is as follows:
[0199] (1) Combine the newly collected data with the historical data to form an updated dataset. (2) Use the updated dataset to retrain the various components of MSAE-MRLF: update the quantum circuit parameters of the quantum attention mechanism; adjust the task weights in the fractal meta-learning algorithm; optimize the control parameters in the chaos strategy; and update the weight calculation method in the adaptive reward mechanism. (3) Verify the performance of the updated model. If the performance improves, save the new model; otherwise, roll back to the previous version. (4) Perform more comprehensive model evaluation and updates regularly (e.g., weekly) to adapt to the long-term changes in Xiao Zhang's sleep pattern.
[0200] Through this continuous learning and optimization approach, the system is able to continuously adapt to Xiao Zhang's personal needs and changes in sleep patterns, providing increasingly personalized and effective sleep assistance services.
[0201] Implementation effect: After several weeks of use, Xiao Zhang's sleep quality has improved significantly. He reported that it took about 20 minutes longer to fall asleep, he woke up less often at night, and he felt more refreshed after waking up. The system records showed that his deep sleep time increased by 15%, and his REM sleep became more regular. Xiao Zhang especially liked the music that the system dynamically adjusted according to his sleep stage, and thought it greatly improved his sleep experience.
[0202] In addition, the system's adaptive ability has also been verified. When Xiao Zhang's sleep pattern changes due to work pressure, the system can quickly adjust its strategy to help him maintain good sleep quality. Xiao Zhang said that this system has become an indispensable part of his daily life and has greatly improved his quality of life.
[0203] The sleep stage-based dynamic music synthesis method and system of the present invention provide users with a highly personalized and effective sleep assistance solution through innovative algorithm design and humanized implementation. It can not only accurately identify the sleep stage, but also dynamically adjust the music parameters according to the user's real-time state to achieve smooth music transition and natural awakening process. The adaptive learning ability of the system ensures long-term effectiveness and can continuously optimize the user's sleep experience. This method and system are expected to play an important role in improving sleep quality and improving the quality of life, and have broad application prospects.
[0204] Please refer to Figure 3 The present invention also discloses a dynamic music synthesis system based on sleep stages, comprising the following modules:
[0205] Data acquisition module 1, this module uses a lightweight EEG device (Neuro SkyMind WaveMobile2) and a motion sensor (Bosch BMI160) to collect the user's EEG data and body movement data. The acquisition frequencies are 512Hz and 100Hz respectively. The collected data is preprocessed by wavelet threshold denoising, improved Z-score normalization and nonlinear principal component analysis (NLPCA) to obtain a standardized feature vector.
[0206] Sleep stage recognition module 2, which uses an improved bidirectional LSTM network (Bi-LSTM) to recognize the user's sleep stage. The network structure includes a 64-dimensional hidden layer and a 5-dimensional output layer (corresponding to 5 sleep stages). LeakyReLU is used as the activation function, and the Adam optimizer is used for training, and the learning rate is set to 0.0001.
[0207] Multi-Scale Spatiotemporal Attention Enhanced Meta-Learning Reinforcement Learning Module 3 (MSAE-MRLF): This is the core module of the system, responsible for dynamically optimizing music parameters. It contains four subcomponents:
[0208] a) Quantum-inspired attention mechanism: 8 qubits are used to construct a 256-dimensional Hilbert space with a quantum circuit depth of 4.
[0209] b) Meta-learning algorithm based on fractal geometry: The fractal dimension is estimated using the box counting method and trained with the Adam optimizer with a learning rate of 0.001.
[0210] c) Hierarchical progressive strategy optimization based on chaos theory: Logistic mapping is used, and the value range of r is [3.57, 4].
[0211] d) Adaptive reward shaping mechanism based on information entropy: dynamically adjust the weights of immediate rewards and long-term rewards.
[0212] Music generation module 4 uses an improved conditional generative adversarial network (C-GAN) to generate music. Both the generator and the discriminator use a deep convolutional neural network structure. The Adam optimizer is used for training, with a learning rate of 0.0002, β1=0.5, and β2=0.999.
[0213] Wake-up planning module 5 uses a fuzzy time series prediction model to classify sleep quality into five fuzzy sets. The max-min composite method is used for prediction, taking into account sleep cycles, personal habits, and external factors.
[0214] Music control module 6: responsible for gradually adjusting music parameters within the predicted optimal wake-up time window to achieve natural wake-up.
[0215] The feedback collection module 7 collects subjective sleep quality scores, objective sleep indicators, music experience feedback and wake-up experience feedback through a user-friendly interface.
[0216] Model updating module 8 uses an incremental learning algorithm to update the MSAE-MRLF framework. The initial value of the learning rate is 0.01 and is dynamically adjusted according to the update effect.
[0217] In order to verify the superiority of the present invention, we conducted a series of comparative experiments. The following is a detailed comparison of Example 1 of the present invention and three comparative examples:
[0218] Example 1: Complete system using the present invention
[0219] Comparative Example 1: Traditional fixed music playback system
[0220] Comparative Example 2: Simple Sleep Stage Recognition + Music Adjustment System (without MSAE-MRLF)
[0221] Comparative Example 3: Dynamic Music Synthesis System Using Traditional Reinforcement Learning
[0222] Test indicators and methods:
[0223] 1. Time to fall asleep (minutes): The time from when the user lies down to when they first enter light sleep, determined by EEG data.
[0224] 2. Sleep efficiency (%): actual sleeping time / total time in bed*100%.
[0225] 3. Deep sleep ratio (%): deep sleep time / total sleep time*100%.
[0226] 4. Number of awakenings at night: determined by EEG and body movement data.
[0227] 5. Subjective sleep quality score (1-10 points): Users rate their sleep quality through the app after waking up.
[0228] 6. Music adaptability score (1-10 points): User's evaluation of the matching degree between music and sleep stage.
[0229] 7. Wake-up comfort (1-10 points): User evaluation of the comfort level of the wake-up process.
[0230] Test results (30-day average):
[0231] The test results are shown in the following table:
[0232] index Example 1 Comparative Example 1 Comparative Example 2 Comparative Example 3 Bedtime 15.3 28.7 22.1 19.8 Sleep efficiency 92.5% 83.2% 87.6% 89.1% Deep sleep ratio 25.8% 18.7% 21.3% 23.2% Number of nighttime awakenings 1.2 3.5 2.4 1.9 Subjective sleep quality rating 8.7 6.2 7.3 7.8 Music adaptability score 9.1 5.8 7.2 8.0 Wake-up comfort 8.9 6.5 7.4 7.9
[0233] Please refer to Figure 7 This radar chart will intuitively show the comprehensive advantages of the present invention in all indicators. In particular, the polygon area of the present invention will be significantly larger than that of other comparative examples, reflecting the superiority of its comprehensive performance. Please refer to Figure 8 , this curve graph will clearly show how the present invention accurately adjusts the music parameters according to the sleep stage, and the curve changes will be smoother and more adaptable. In contrast, the curve of comparative example 1 may be a straight line (fixed parameters), the curve of comparative example 2 may show a step-like change (simple switching), and the curve of comparative example 3 may change but is not as accurate and smooth as the present invention.
[0234] Example 1 (the complete system of the present invention) performs best in all test indicators, fully demonstrating the superiority of the present invention:
[0235] 1. The time to fall asleep is significantly shortened: 13.4 minutes faster than the traditional system and 4.5 minutes faster than the closest comparison example 3, indicating that the MSAE-MRLF framework can more accurately generate suitable music for the sleeping stage.
[0236] 2. Improved sleep efficiency: reaching 92.5%, 9.3 percentage points higher than the traditional system, indicating that this system can effectively reduce ineffective bed rest time and improve sleep quality.
[0237] 3. Increased deep sleep ratio: The deep sleep ratio of 25.8% is close to the ideal level (20-25%), which is 2.6-7.1 percentage points higher than other solutions, proving that this system can better promote deep sleep.
[0238] 4. Fewer awakenings at night: an average of only 1.2 times, 2.3 times less than the traditional system, indicating that the music generated by this system can better maintain sleep continuity.
[0239] 5. The subjective sleep quality score is the highest: 8.7 points is much higher than other solutions, indicating that users' overall perception of sleep quality has significantly improved.
[0240] 6. Music adaptability scored the highest: The high score of 9.1 proves that the MSAE-MRLF framework can accurately adjust music according to sleep stages, providing an excellent user experience.
[0241] 7. Highest wake-up comfort: The score of 8.9 points shows that the wake-up planning module of this system works well and can wake up users at the best time.
[0242] These results fully demonstrate the effectiveness of the core innovation of this invention, the MSAE-MRLF framework. The framework captures subtle features in sleep data through a quantum-inspired attention mechanism, improves the adaptability of the system through a meta-learning algorithm based on fractal geometry, increases the diversity of strategy optimization through the introduction of chaos theory, and effectively solves the problem of reward sparsity in reinforcement learning through an adaptive reward mechanism based on information entropy.
[0243] Compared with Comparative Example 3 using traditional reinforcement learning, the present invention has obvious advantages in all indicators, especially in music adaptability and wake-up comfort, which are 1.1 points and 1.0 points higher respectively. This shows that the MSAE-MRLF framework can more accurately capture the dynamic changes of sleep, generate more suitable music, and wake up the user at the best time.
[0244] In summary, these test results not only verify the significant effect of the present invention in improving sleep quality, but also prove the innovation and superiority of its core technology MSAE-MRLF framework in the field of dynamic music synthesis and sleep assistance. This dynamic music synthesis method based on sleep stages provides a new and efficient solution for non-drug treatment of sleep disorders.
[0245] It should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A dynamic music synthesis method based on sleep stages, characterized in that: The following steps are involved: Acquire user sleep data; identify the user's sleep stage based on the user sleep data; dynamically optimize music parameters according to the sleep stage using a multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework; generate music based on the optimized music parameters and achieve smooth transition; during the music playback process, continuously monitor the user's sleep state and predict the optimal wake-up time window; when the optimal wake-up time window is detected, adjust the music parameters to promote the user to wake up naturally; after the user wakes up, collect user feedback; update the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework based on the user feedback; repeat the above steps to continuously optimize the user's sleep experience.
2. The method according to claim 1, characterized in that The obtaining of the user's sleep data comprises: using a lightweight EEG device and a motion sensor to collect EEG data and motion data; performing noise reduction processing on the EEG data and motion data to obtain noise-reduced data, wherein the noise reduction processing adopts a wavelet threshold denoising algorithm, and its formula is: ψ j,k (t)=2 (j / 2) ψ(2 j tk) Where ψ is a wavelet function, j is a scale, k is a translation parameter, and t is a time variable; the denoised data is normalized to obtain normalized data, wherein the normalization process adopts an improved Z-score normalization, and the formula is: Where x is the original data, μ is the mean, σ is the standard deviation, and ∈ is a small positive number (1e-8); feature extraction is performed on the normalized data to obtain a feature vector; wherein the feature vector is used as input for subsequent steps.
3. The method according to claim 1, characterized in that The method for identifying the sleep stage of a user adopts an improved bidirectional LSTM network, and the algorithm steps include: 1) Initialize network parameters W f ,W b ,W o ,b f ,b b ,b o ; (2) For the input sequence X = [x1, x2, ..., x T ], calculate the forward hidden state: (3) Calculate the backward hidden state: (4) Calculate the output layer: Among them, σ is the activation function, x t is the input feature vector, and are the forward and backward hidden states, y t Output sleep stage probability distribution.
4. The method according to claim 1, characterized in that: The method of generating music based on the optimized music parameters and achieving smooth transition adopts an improved conditional generative adversarial network (C-GAN), and its algorithm steps include: (1) Initialize the parameters of the generator G and the discriminator D; (2) Generator G generates music clips: G(z,c)=tanh(W g [z,c]+b g ) (3) The discriminator D distinguishes real music from generated music: D(x,c) = σ(W d [x,c]+b d ) (4) Optimize the objective function: min G max D V(D,G)=E x [logD(x|c)]+E z [log(1-D(G(z|c)))]+λL smooth Among them, z is random noise, c is the conditional vector (including music parameters and sleep stage information), x is the real music sample, and W g ,W d ,b g ,b d is a learnable parameter, λ is the weight of the smooth loss term, L smooth is a smooth loss function.
5. The method according to claim 1, characterized in that The prediction of the optimal wake-up time window adopts a fuzzy time series prediction model, and its algorithm steps include: (1) Define fuzzy sets: (2) Establish fuzzy logic relationship: R i =A i →A i+1 (3) Predict the state at the next moment: F(t+1)=A i R i Among them, A i represents a fuzzy set, is the membership function, u j is an element in the domain, R i is the fuzzy logic relationship matrix, and F(t+1) is the prediction result.
6. The method according to claim 1, characterized in that The multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework is updated based on the user feedback using an incremental learning algorithm, and its update formula is: Among them, θ is the model parameter, η is the learning rate, and D n ew is the newly collected data, L is the loss function, represents the gradient with respect to θ.
7. The method according to claim 1, characterized in that The multi-scale spatiotemporal attention-enhanced meta-learning reinforcement learning framework includes: a quantum-inspired attention mechanism; a meta-learning algorithm based on fractal geometry; a hierarchical progressive strategy optimization based on chaos theory; and an adaptive reward shaping mechanism based on information entropy.
8. The method according to claim 7, characterized in that The algorithm steps of the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework include: (1) Constructing quantum state representation based on the quantum-inspired attention mechanism Among them, |t i >Quantum state representing time characteristics, |s j > quantum state representing spatial characteristics, α ij is the complex amplitude; (2) Define the quantum evolution operator U and calculate the attention weight: A=|<ψ|U|ψ>| 2 Among them, U is a unitary matrix, representing the evolution of the quantum system; (3) Calculate the fractal dimension based on the meta-learning algorithm of fractal geometry Where N is the number of hyperspheres required to cover the set, r is the radius of the hypersphere, (4) Define the meta-learning objective function: Among them, w i is the task weight, D i is the fractal dimension of the task, L i is the task loss function, θ is the model parameter; (5) Based on the hierarchical progressive strategy optimization of the chaos theory, the chaotic sequence is calculated: x n+1 =r·x n ·(1-x n ) Among them, r is the control parameter, x n ∈[0,1]; (6) Update global and local strategies: Among them, α and β are learning rates, J(θ) and J(φ) are the objective functions of the global and local strategies respectively, and C(x n ) is the chaos metric function; (7) Based on the adaptive reward shaping mechanism of the information entropy, the information entropy of the state is calculated: Where p(x) is the probability distribution of state x; (8) Calculate adaptive rewards: w1=σ(H(s t )-H(s t-1 )) w2=1-w1 Among them, r immediate For immediate reward, r l ong_term is the long-term reward, H(s t ) and H(s t-1 ) are the information entropy of the current state and the previous state respectively; 9) Optimizing music parameters based on the attention weights, the meta-learning objective function, the updated strategy, and the adaptive reward.
9. The method according to claim 8, characterized in that The optimization process of the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning framework further includes: (1) Initialize model parameters θ and φ; (2) For each time step t: a) Get the current status s t ; b) Use the quantum attention mechanism to calculate the attention weight A t ; c) Calculate the fractal dimension D of the current task based on fractal geometry t ; d) Generate x using chaos map n sequence; e) Calculate the global action a global =π global (s t ) and local action a local =π local (s t _; f) Execute action a t =w g ·a global +(1-w g )·a local , where w g is the global action weight, Observe the next state s t +1 and reward r t ; h) Calculate the adaptive reward R t ; i) Update the experience replay buffer D; (3) Sample small batches of data from D for training: a) Calculate the target Q value: y i =R i +γ·max a Q(s i+1 ,a;θ′) b) Update Q network parameters: c) Update the target network parameters: θ′=τ·θ+(1-τ)·θ′(4) Update the meta-learning parameters: Among them, γ is the discount factor, η is the learning rate, τ is the target network soft update parameter, η meta is the meta-learning rate.
10. A dynamic music synthesis system based on sleep stages, characterized in that: include: A data collection module for obtaining user sleep data; A sleep stage identification module connected to the data acquisition module and configured to identify the user's sleep stage based on the user's sleep data; A multi-scale spatiotemporal attention-enhanced meta-learning reinforcement learning module connected to the sleep stage recognition module for dynamically optimizing music parameters according to the sleep stage; A music generation module connected to the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module, used to generate music based on the optimized music parameters and achieve smooth transition; a wake-up planning module connected to the music generation module and the data acquisition module, used to continuously monitor the user's sleep state during music playback and predict the optimal wake-up time window; a music control module connected to the wake-up planning module and the music generation module, used to adjust the music parameters to promote the user's natural wake-up when the optimal wake-up time window is detected; a feedback collection module used to collect user feedback after the user wakes up; A model updating module connected to the feedback collection module and the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module, and used to update the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module based on the user feedback; wherein, the system continuously optimizes the user's sleep experience by cyclically executing the functions of the above modules, and the multi-scale spatiotemporal attention enhanced meta-learning reinforcement learning module adopts the method described in any one of claims 1-9 to optimize music parameters.