Federated learning method and system suitable for carbon credit evaluation, electronic device, and computer readable storage medium
A federated learning method includes: obtaining a target federated sub-model of a target participating node, the target federated sub-model being obtained upon dividing up a federated model, the federated model comprising at least three federated sub-models, and the target federated sub-model comprising a model parameter and a target feature of the target participating node; obtaining a current network delay and preset instances of optimization of the target feature; determining current instances of optimization on the basis of the difference between the current network delay and a preset network delay corresponding to the preset instances of optimization; performing local optimization on the target feature according to the current instances of optimization; and performing encrypted interaction of an optimization result of the target feature with other participating nodes, so as to optimize a model parameter and determine a target model parameter of the target federated sub-model.
1 . A federated learning method for carbon credit evaluation, performed by an electronic device of a target participating node, the method comprising:
obtaining a target federated sub-model of the target participating node, wherein the target federated sub-model is obtained by splitting a federated model comprising at least three federated sub-models, and the target federated sub-model comprises a model parameter and a target feature of the target participating node;
obtaining a present network delay and a preset number of optimizations of the target feature;
determining a present number of optimizations based on a difference between the present network delay and a preset network delay corresponding to the preset number of optimizations, wherein
the present number of optimizations is calculated by the following formula:
F
L
=
F
B
*
(
1
+
T
L
-
T
B
T
B
)
where F B represents the preset number of optimizations, F L represents the present number of optimizations, T B represents the preset network delay corresponding to the preset number of optimizations, and T L represents the present network delay;
locally optimizing the target feature based on the present number of optimizations to obtain an optimization result of the target feature; and
performing encrypted interaction on the optimization result of the target feature with electronic devices of other participating nodes, to optimize the model parameter to determine a target model parameter of the target federated sub-model,
wherein performing the encrypted interaction on the optimization result of the target feature with the electronic devices of the other participating nodes comprises:
calculating a public key and a private key based on a homomorphic encryption algorithm, and sending the public key to the electronic devices of the other participating nodes;
calculating a product of the optimization result of the target feature and the model parameter corresponding to the target federated sub-model and a square of the product of the optimization result of the target feature and the model parameter, and sending the product and the square of the product to the electronic devices of the other participating nodes; and
sending a ciphertext gradient encrypted with a public key of a specified participating node to the electronic devices of all other participating nodes,
the method further comprising: before sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receiving a product of a model parameter and a respective target feature and the square of the product of the model parameter and the respective target feature encrypted by each of the electronic devices of the other participating nodes with the public key of the specified participating node;
determining a ciphertext objective function based on the received product and square of the product sent by each of the electronic devices of the other participating nodes; and
calculating the ciphertext gradient of the target participating node based on the ciphertext objective function, wherein the ciphertext gradient is encrypted with the public key of the specified participating node, and the ciphertext objective function is calculated by the following formula:
[
L
]
=
∑
i
=
1
N
-
y
i
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
2
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
8
[
(
u
i
A
)
2
]
+
1
8
[
(
u
i
B
)
2
]
+
1
8
[
(
u
i
C
)
2
]
+
1
4
[
u
i
A
×
u
i
B
]
+
1
4
[
u
i
B
×
u
i
C
]
+
1
4
[
u
i
A
×
u
i
C
]
and the ciphertext gradient of the target participating node is:
[
∂
L
∂
θ
C
]
A
=
∑
i
=
1
N
-
[
y
i
x
i
C
]
+
1
2
[
x
i
C
]
+
1
4
[
u
i
C
x
i
C
]
+
1
4
[
u
i
A
x
i
C
]
+
1
4
[
u
i
B
x
i
C
]
where L represents the ciphertext objective function, y i represents a global model prediction value, θ represents a model parameter of a federated sub-model corresponding to a participating node, x i represents a target feature corresponding to a participating node,
u
i
A
=
θ
A
x
i
A
,
u
i
B
=
θ
B
x
i
B
,
u
i
C
=
θ
C
x
i
C
,
θ C represents the model parameter of the target federated sub-model,
x
i
C
represents the target feature of the target participating node, and
[
∂
L
∂
θ
C
]
A
represents the ciphertext gradient encrypted with the public key of the specified participating node,
and the method further comprising: after sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receiving a gradient result obtained by each of the electronic devices of the other participating nodes decrypting the ciphertext gradient of the target participating node, to determine the target model parameter of the target federated sub-model.
2 . The method of claim 1 , further comprising: before obtaining the target federated sub-model of the target participating node,
extracting a data feature from a data set as an original data feature;
calculating an information entropy of the data feature, and calculating an attribute importance degree of the data feature based on the information entropy, to optimize the data feature and obtain a data depth feature; and
fusing the original data feature and the data depth feature to obtain the target feature of the target participating node.
3 . The method of claim 2 , wherein the information entropy is calculated by the following formula:
H
(
X
)
=
E
[
p
(
a
1
)
,
p
(
a
2
)
,
…
,
p
(
a
n
)
]
=
-
∑
j
=
1
n
p
(
a
i
)
log
2
p
(
a
i
)
where p(a i ) represents a probability of each discrete message occurred, H max (x i ) is H(X)=log 2 n, representing a maximum information entropy; and
the attribute importance degree is calculated by the following formula:
A
I
i
=
H
m
ax
(
x
i
)
-
H
(
x
i
)
H
ma
x
(
x
i
)
where AI i represents the attribute importance degree, H max (x i ) represents the maximum information entropy and H(x i ) represents an attribute information entropy.
4 . The method of claim 1 , further comprising:
sending an encrypted authorization request for the federated sub-model to the electronic devices of the other participating nodes;
verifying each of the other participating nodes based on a smart contract and determining whether to authorize the respective participating node, and sending an authorization token to the electronic devices of the other participating nodes based on a determination result; and
receiving authorization tokens from the electronic devices of the other participating nodes to complete an on-chain authorization of the federated sub-model.
5 . An electronic device, comprising
a memory for storing computer instructions; and
a processor, wherein
the memory is communicatively connected to the processor; and
the processor is configured to execute the computer instructions to perform the following operations:
obtaining a target federated sub-model of a target participating node, wherein the target federated sub-model is obtained by splitting a federated model comprising at least three federated sub-models, and the target federated sub-model comprises a model parameter and a target feature of the target participating node;
obtaining a present network delay and a preset number of optimizations of the target feature;
determining a present number of optimizations based on a difference between the present network delay and a preset network delay corresponding to the preset number of optimizations, wherein
the present number of optimizations is calculated by the following formula:
F
L
=
F
B
*
(
1
+
T
L
-
T
B
T
B
)
where F B represents the preset number of optimizations, F L represents the present number of optimizations, T B represents the preset network delay corresponding to the preset number of optimizations, and T L represents the present network delay;
locally optimizing the target feature based on the present number of optimizations to obtain an optimization result of the target feature; and
performing encrypted interaction on the optimization result of the target feature with electronic devices of other participating nodes, to optimize the model parameter to determine a target model parameter of the target federated sub-model,
wherein the processor is further configured to:
calculate a public key and a private key based on a homomorphic encryption algorithm, and send the public key to the electronic devices of the other participating nodes;
calculate a product of the optimization result of the target feature and the model parameter corresponding to the target federated sub-model and a square of the product of the optimization result of the target feature and the model parameter, and send the product and the square of the product to the electronic devices of the other participating nodes; and
send a ciphertext gradient encrypted with a public key of a specified participating node to the electronic devices of all other participating nodes,
wherein the processor is further configured to: before sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receive a product of a model parameter and a respective target feature and the square of the product of the model parameter and the respective target feature encrypted by each of the electronic devices of the other participating nodes with the public key of the specified participating node;
determine a ciphertext objective function based on the received product and square of the product sent by each of the electronic devices of the other participating nodes; and
calculate the ciphertext gradient of the target participating node based on the ciphertext objective function, wherein the ciphertext gradient is encrypted with the public key of the specified participating node, and the ciphertext objective function is calculated by the following formula:
[
L
]
=
∑
i
=
1
N
-
y
i
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
2
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
8
[
(
u
i
A
)
2
]
+
1
8
[
(
u
i
B
)
2
]
+
1
8
[
(
u
i
C
)
2
]
+
1
4
[
u
i
A
×
u
i
B
]
+
1
4
[
u
i
B
×
u
i
C
]
+
1
4
[
u
i
A
×
u
i
C
]
and the ciphertext gradient of the target participating node is:
[
∂
L
∂
θ
C
]
A
=
∑
i
=
1
N
-
[
y
i
x
i
C
]
+
1
2
[
x
i
C
]
+
1
4
[
u
i
C
x
i
C
]
+
1
4
[
u
i
A
x
i
C
]
+
1
4
[
u
i
B
x
i
C
]
where L represents the ciphertext objective function, y i represents a global model prediction value, θ represents a model parameter of a federated sub-model corresponding to a participating node, x i represents a target feature corresponding to a participating node,
u
i
A
=
θ
A
x
i
A
,
u
i
B
=
θ
B
x
i
B
,
u
i
C
=
θ
C
x
i
C
,
θ C represents the model parameter of the target federated sub-model,
x
i
C
represents the target feature of the target participating node, and
[
∂
L
∂
θ
C
]
A
represents the ciphertext gradient encrypted with the public key of the specified participating node,
wherein the processor is further configured to: after sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receive a gradient result obtained by each of the electronic devices of the other participating nodes decrypting the ciphertext gradient of the target participating node, to determine the target model parameter of the target federated sub-model.
6 . A non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium has stored thereon computer instructions which, when being executed by a computer, cause the computer to perform the following operations:
obtaining a target federated sub-model of a target participating node, wherein the target federated sub-model is obtained by splitting a federated model comprising at least three federated sub-models, and the target federated sub-model comprises a model parameter and a target feature of the target participating node;
obtaining a present network delay and a preset number of optimizations of the target feature;
determining a present number of optimizations based on a difference between the present network delay and a preset network delay corresponding to the preset number of optimizations, wherein
the present number of optimizations is calculated by the following formula:
F
L
=
F
B
*
(
1
+
T
L
-
T
B
T
B
)
where F B represents the preset number of optimizations, F L represents the present number of optimizations, T B represents the preset network delay corresponding to the preset number of optimizations, and T L represents the present network delay;
locally optimizing the target feature based on the present number of optimizations to obtain an optimization result of the target feature; and
performing encrypted interaction on the optimization result of the target feature with electronic devices of other participating nodes, to optimize the model parameter to determine a target model parameter of the target federated sub-model,
wherein the computer instructions which, when being executed by the computer, causes the computer to:
calculate a public key and a private key based on a homomorphic encryption algorithm, and send the public key to the electronic devices of the other participating nodes;
calculate a product of the optimization result of the target feature and the model parameter corresponding to the target federated sub-model and a square of the product of the optimization result of the target feature and the model parameter, and send the product and the square of the product to the electronic devices of the other participating nodes; and
send a ciphertext gradient encrypted with a public key of a specified participating node to the electronic devices of all other participating nodes,
wherein the computer instructions which, when being executed by the computer, causes the computer to: before sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receive a product of a model parameter and a respective target feature and the square of the product of the model parameter and the respective target feature encrypted by each of the electronic devices of the other participating nodes with the public key of the specified participating node;
determine a ciphertext objective function based on the received product and square of the product sent by each of the electronic devices of the other participating nodes; and
calculate the ciphertext gradient of the target participating node based on the ciphertext objective function, wherein the ciphertext gradient is encrypted with the public key of the specified participating node, and the ciphertext objective function is calculated by the following formula:
[
L
]
=
∑
i
=
1
N
-
y
i
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
2
(
[
u
i
A
]
+
[
u
i
B
]
+
[
u
i
C
]
)
+
1
8
[
(
u
i
A
)
2
]
+
1
8
[
(
u
i
B
)
2
]
+
1
8
[
(
u
i
C
)
2
]
+
1
4
[
u
i
A
×
u
i
B
]
+
1
4
[
u
i
B
×
u
i
C
]
+
1
4
[
u
i
A
×
u
i
C
]
and the ciphertext gradient of the target participating node is:
[
∂
L
∂
θ
C
]
A
=
∑
i
=
1
N
-
[
y
i
x
i
C
]
+
1
2
[
x
i
C
]
+
1
4
[
u
i
C
x
i
C
]
+
1
4
[
u
i
A
x
i
C
]
+
1
4
[
u
i
B
x
i
C
]
where L represents the ciphertext objective function, y i represents a global model prediction value, θ represents a model parameter of a federated sub-model corresponding to a participating node, x i represents a target feature corresponding to a participating node,
u
i
A
=
θ
A
x
i
A
,
u
i
B
=
θ
B
x
i
B
,
u
i
C
=
θ
C
x
i
C
,
θ C represents the model parameter of the target federated sub-model,
x
i
C
represents the target feature of the target participating node, and
[
∂
L
∂
θ
C
]
A
represents the ciphertext gradient encrypted with the public key of the specified participating node,
wherein the computer instructions which, when being executed by the computer, causes the computer to: after sending the ciphertext gradient encrypted with the public key of the specified participating node to the electronic devices of all other participating nodes,
receive a gradient result obtained by each of the electronic devices of the other participating nodes decrypting the ciphertext gradient of the target participating node, to determine the target model parameter of the target federated sub-model.
7 . The electronic device of claim 5 , wherein the processor is further configured to: before obtaining the target federated sub-model of the target participating node,
extract a data feature from a data set as an original data feature;
calculate an information entropy of the data feature, and calculate an attribute importance degree of the data feature based on the information entropy, to optimize the data feature and obtain a data depth feature; and
fuse the original data feature and the data depth feature to obtain the target feature of the target participating node.
8 . The electronic device of claim 7 , wherein the information entropy is calculated by the following formula:
H
(
X
)
=
E
[
p
(
a
1
)
,
p
(
a
2
)
,
…
,
p
(
a
n
)
]
=
-
∑
j
=
1
n
p
(
a
i
)
log
2
p
(
a
i
)
where p(a i ) represents a probability of each discrete message occurred, H max (x i ) is H(X)=log 2 n, representing a maximum information entropy; and
the attribute importance degree is calculated by the following formula:
A
I
i
=
H
m
ax
(
x
i
)
-
H
(
x
i
)
H
m
ax
(
x
i
)
where AI i represents the attribute importance degree, H max (x i ) represents the maximum information entropy and H(x i ) represents an attribute information entropy.
9 . The electronic device of claim 5 , wherein the processor is further configured to:
send an encrypted authorization request for the federated sub-model to the electronic devices of the other participating nodes;
verify each of the other participating nodes based on a smart contract and determining whether to authorize the respective participating node, and send an authorization token to the electronic devices of the other participating nodes based on a determination result; and
receive authorization tokens from the electronic devices of the other participating nodes to complete an on-chain authorization of the federated sub-model.
10 . The non-transitory computer-readable storage medium of claim 6 , wherein the computer instructions which, when being executed by the computer, cause the computer to: before obtaining the target federated sub-model of the target participating node,
extract a data feature from a data set as an original data feature;
calculate an information entropy of the data feature, and calculate an attribute importance degree of the data feature based on the information entropy, to optimize the data feature and obtain a data depth feature; and
fuse the original data feature and the data depth feature to obtain the target feature of the target participating node.
11 . The non-transitory computer-readable storage medium of claim 10 , wherein the information entropy is calculated by the following formula:
H
(
X
)
=
E
[
p
(
a
1
)
,
p
(
a
2
)
,
…
,
p
(
a
n
)
]
=
-
∑
j
=
1
n
p
(
a
i
)
log
2
p
(
a
i
)
where p(a i ) represents a probability of each discrete message occurred, H max (x i ) is H(X)=log 2 n, representing a maximum information entropy; and
the attribute importance degree is calculated by the following formula:
A
I
i
=
H
ma
x
(
x
i
)
-
H
(
x
i
)
H
m
ax
(
x
i
)
where AI i represents the attribute importance degree, H max (x i ) represents the maximum information entropy and H(x i ) represents an attribute information entropy.